-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
TLDR: Error messages in the REPL can get very long and have low signal to noise ratio. Maybe there should be an option to determine how they are printed?
I don't know if this could be considered a "julep" but I think it would be good to have a discussion about the error messages we print. There are two main reasons that I think causes large error messages in Julia:
- Multiple dispatch encourages many methods with small bodies that for example just converts and argument and then calls another method of the same function. This leads to quite deep stack traces.
- Parameterization of types that might be arbitrarily nested leads to types that when printed in full detail can easily take > 50 characters.
- Inlined methods are now shown in the backtrace
The combination of the points above leads to backtraces that for me at least commonly look like this. While sometimes being good to have all the details i personally often get lost in this "Red Sea" looking for the line in my own code where the problem is.
I believe a one size fits all approach for printing errors is not going to work due to different demands in different situation so what is needed is to let the user have some control over the way the errors are printed. A few questions that naturally arises are:
- What options should there be? What should be default?
- How should these option flow through the
showerrorfunctions and theshowfunction for aStackFrame? CouldIOContextbe used for that? - How should the options be controlled. ENV variables? Some global state? This is related to the previous point.
Right now, I would say that the biggest source of noise are the types of the function arguments in the backtrace. I am almost never interested in them and if happen to be I could just go to the source location and look at them. Having an option to not print those would get a long way.
I have experimented a bit in a package that just rudely overwrites a few methods in Base so that you can set some options in https://github.com/KristofferC/ErrorMessages.jl.
Some other random suggestions / ideas:
- Instead of printing the whole error message in red, perhaps we can exploit a few more colors. Function definition in one color, arguments in another and the file location in another?
- Should the file information be printed on a separate indented line from the function definition?
- Should the backtrace actually be printed in reverse order so that the function on top of the stack is the one closest to the new prompt line. It is awkward when you have to scroll up to see where the error actually got thrown
Would be interesting to hear your ideas / comments. :)