Inspired by a real situation that isn't interesting. Suffice to say that I'm both the author and user of the program and the errors represent bugs I need to fix, so I'm interested in every error, but there may be a lot of them.
Some precepts:
- An error can be more than one line. Do not conflate “errors” with “lines of error output”. By “error”, I mean “one discrete thing that went wrong”, regardless of how many lines are used to display it.
- I'm primarily thinking of a command-line program (because that's what I'm writing) and communicating the breadth of errors without spamming the terminal.
- The errors in question may be heterogenous, so the first n are not necessarily representative of the full set of them.
- The errors are independent; no error is the cause of another error (though they may be caused by the same underlying fault).
The naïve way to handle this would be to just spam them out to the console without a care in the world, but I had some ideas this morning for how to make this more humane.
1. Accumulate errors in a buffer.
Instead of printing them one at a time as they occur, stack 'em up in a list/array, then print all or some of them at the end.
If you want (or need) to limit memory, have a soft cap of n and a hard cap of n×2. If you hit the hard cap, drop every other error.
You could do a factor m that is more than two, in which case you'd drop all but 1/m'th of the errors. E.g., if m=5, you drop four errors out of every five.
Keep a running count of how many were actually encountered before any omissions, and include this in your output.
2. If more than 5 errors, print the interquartile errors.
That is, only print the first, n×1/4, n×2/4, n×3/4, and nth errors. Also print the full count.
3. Bonus idea: Full log of everything.
The moment you hit the soft cap, open a file and start writing every error to it. This preserves the full set of errors in case the user wants/needs to go digging, or in case they're intermittent.
In a terminal-based tool, you can print the path after your sample of five. In a GUI app, you can have a button to reveal the file in the Finder/Explorer/other file-system-navigator.