-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: print error messages in REPL with colors and structure #18228
Conversation
I think the extra space and showing the function and filename in different colors are good; makes it much easier to spot the source locations. I'd rather not use too many different colors though. Maybe something like bold for the function name and source location? |
@JeffBezanson like so? |
I like that a bit better; will see what others think. I think if we're going to reverse the order of the stack trace the |
"from" instead of "in"? |
Nevermind, just bullets is better. |
Maybe just the function name bold, not its arguments? E.g. h(::Float64) instead of h(::Float64). |
Yes, I have a new version coming up that I think wil be better. |
Having the file and line-number in a different color would be helpful. Or maybe just bold if the arguments become non-bold as per @martinholters suggestion. |
New suggestion (thx to @jakebolewski for inspiration):
|
Very readable. The backtrace ordering needs some getting-used-to, but IMHO makes a lot of sense this way. |
FWIW this also exists now by just using the package at https://github.com/KristofferC/PimpMyREPL.jl so it is possible to try it out without having to mess with rebuilding and merging into a local branch. |
Also, the stacktrace is printed with the in the reverse order from previously and with the error message at the very bottom. | ||
The rationale behind this is that it puts the relevant info closer to the cursor so one does not need to scroll up. | ||
* The REPL now prints errors with more structure and more color. | ||
Also, the stacktrace is printed with the in the reverse order from previously and with the error message at the very bottom. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"with the in the"
Maybe "in reverse order compared to previous releases"?
+1 in general! I'm not a fan of the horizontal line at the top, though. If people really want to keep it, at least use the Unicode box drawing character Also, how about printing numbered bullets? They would make it easier to sport the most recent call (though "most recent call last" is already printed). |
About the colors, I really liked the yellow, but I'm fine with white bold, @KristofferC would there be an API to change the color scheme and make new themes? |
@@ -110,15 +110,19 @@ function ip_matches_func(ip, func::Symbol) | |||
return false | |||
end | |||
|
|||
error_file_color = :green | |||
error_funcdef_color = :yellow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Remove
@Ismael-VC There is (yet to be documented, if people think it should be a setting): https://github.com/JuliaLang/julia/pull/18228/files#diff-8d2b8a22d475d81e3a1944aedb57ad42R60 |
@nalimilan Why would numbers make it easier to spot the most recent call? It is always at the bottom. Also it is not obvious if a 1 represents the bottom or the top of the stack. Regarding the line, I kinda like it because without it the last command and the error sort of gets clumped together. Without it, it also makes the |
# Only print the backtrace header if there actually is a printed backtrace | ||
if backtrace_str != "" | ||
header = string(typeof(ex).name.name) | ||
line_len = 76 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be dependant of the terminal width rather than a fixed size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like min(displaysize(io)[2], 90)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just without the 90 minimum since otherwise it would print a partially wrapped line of -
s when the terminal is narrower that 90.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant max
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err... or wait...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, hmm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would displaysize(STDOUT)
be valid...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base.Terminals.width(Base.active_repl.t)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably good with an extra space in header
I'm not fond of the line, I'd prefer either a blank line or that it'd occupy the same width as the julia prompt for example. That aside, this is looking really good so far! |
The blank line seems like wasted space to me. Also need to double-check whether the unicode symbols will show up properly in Windows prompts. Looks okay in Windows 10 but might not be in 7. edit: nope, |
From @nalimilan suggestion about numbering the frames I implemented something fun in |
What would folks think of putting the descriptive error at the top, e.g. julia> test_error()
BoundsError: attempt to access 5-element Array{Float64,1} at index [6]
─────────────────────────────────────────────────────────────────────────────────
BoundsError Stack trace (most recent call last)
- test_error()
└ at ErrorMessages.jl:172
- h(::Float64)
└ at ErrorMessages.jl:162
─────────────────────────────────────────────────────────────────────────────────
julia> ? Could also draw another line beneath the stack trace to better visually separate it from the user's commands, as shown above. |
print(io, f) | ||
else | ||
print(io, "(::", ft, ")") | ||
isreplerror = get(io, :REPLError, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a better name for this would be :hascolor
? REPLError sounds both too specific and too vague to me.
@@ -201,15 +201,19 @@ function show_spec_linfo(io::IO, frame::StackFrame) | |||
end | |||
|
|||
function show(io::IO, frame::StackFrame; full_path::Bool=false) | |||
print(io, " in ") | |||
isreplerror = get(io, :REPLError, false) | |||
print(io, isreplerror ? " ─ " : " in ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels unfortunate. I think we could add a second kwarg prefix = " in "
instead, since the only place this is called with REPLError = true
is show_backtrace -> show_trace_entry
?
Please forgive me if I'm wrong, but I thought the consensus was to put the error text at the bottom? In your example, the red Also I'd still love to see some dividing lines but that's just personal taste. :) |
That only makes sense if the traces are reversed though. And that I feel is a too big change right now. Thanks for the comments @vtjnash. Lovely to get some input on the implementation. I had a hard time knowing how much to branch on IOContext vs keywords. Will update in a while. |
6a48239
to
f546514
Compare
How about something like this @vtjnash? |
f546514
to
8d15273
Compare
Also, do you think the |
@@ -61,6 +63,8 @@ warn_color() = repl_color("JULIA_WARN_COLOR", default_color_warn) | |||
info_color() = repl_color("JULIA_INFO_COLOR", default_color_info) | |||
input_color() = text_colors[repl_color("JULIA_INPUT_COLOR", default_color_input)] | |||
answer_color() = text_colors[repl_color("JULIA_ANSWER_COLOR", default_color_answer)] | |||
stackframe_linfo_color() = repl_color("JULIA_STACKFRAME_LINFO_COLOR", :bold) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spell out lineinfo ?
It's a bit awkward to have both a global variable for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing what happens if I leave another neutral "comment" review when I had previously approved an older version of this
I'm a little concerned about the ballooning number of environment variables. I feel like we should use a TOML config file instead and use an environment variable to indicate which file to load. |
Ref #2716 |
I could just take away the config options but for frontends that can do color but not boldness (like jupyter notebook) it might be good to give an option. I wouldn't mind redoing the whole color customization configuration into a julia functional API but might not be worth it. |
yes, I think the global should go away |
This seems to need a rebase and maybe a little design discussion. |
a248031
to
4dc6f35
Compare
Rebased. Design comments are welcome. |
Mac seems to include an extra space for some reason, hence the test error:
|
@KristofferC: I think you should just use your judgement here and pick the style you like. If people hate it, I'm sure we'll hear about it. |
I will open a new PR since there is so much previous discussion here that is no longer directly relevant, and many things have changed along the way. |
Follow up to #18215 which after discussion was closed because hiding relevant information is not a good thing. This instead tries to show the same information as we currently do but with a bit more structure.
For the same example as in #18215:
I am not sure that the colors I chose are the best but I am not an artist... Previous way of showing errors are retrieved by an
ENV
variable:Things to bikeshed over