-
-
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
Try make REPL error easier to visually parse #19569
Conversation
n_frames = 0 | ||
frame_counter = 0 | ||
process_backtrace((a,b) -> n_frames += 1, t) | ||
n_frames != 0 && print(io, "\n\nStacktrace:") |
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 only one newline here?
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.
Sure.
Having both the frame numbering and REPL inputs numbered in [n] format could be a bit confusing, maybe change to parens for one of them? |
I think they're visually different enough here to be clear. |
Also, let's not let relatively trivial style bikeshedding derail this again. This is a huge improvement over the current state of affairs and we can tweak it after the major part of the change is merged. |
The doctests in docstrings containing stacktraces will need updating to the new style. Probably best to rebase over #19562 to avoid seeing doctest errors that I've already fixed. |
I'm having some troubles with the doctests. For example:
I can't see any difference between them. Is it whitespace sensitive or? |
Missing |
How could I not notice!? I looked at it for like a minute... |
6697dc2
to
2d6643e
Compare
I just have plenty of practise reading that kind of output... really needs to be improved though. |
Tests pass, ready for a second, third etc. set of eyes. |
Do the tests pass when color is disabled? Are the env vars documented anywhere? |
Color is always disabled in tests, therefore I have to "fool" julia that they are enabled with the eval stuff in the tests. The env vars are not documented, because I am not sure if that level of customization is needed. @StefanKarpinski also expressed concerns that the number of env variables are getting maybe a bit too many. They don't really bloat the code so should be fine to keep. |
I'm fine with using environment variables as an interim thing, but we need a better approach. |
If possible I would like to wait with documenting / removing the env variables. If people hate this and we revert it, it is work for nothing. |
Could this be extended to errors in scripts (outside REPL) too? |
If you run the script in the REPL then it will also have this output if that is what you mean. So not only for functions defined in the REPL. |
@KristofferC Actually, I meant scripts outside the REPL, run from the shell, like:
|
Ah, I see. I am not sure where the error is actually thrown from in that case. Maybe from the c code? |
ead09b2
to
8c514ef
Compare
Rebased. AV failure is in pkg with some network problems. |
I do think that @cossio has a good point about that backtraces should look as similar as possible no matter if excpetions are thrown (and caught) in the REPL or by the julia runtime (if that is the correct vocabulary) which then makes execution stop. I tried to look a bit in the c-code ( |
All errors are thrown by |
@cossio I am a bit confused because this does already seems to work when running files from the shell, i.e.
|
@KristofferC will it be colored as well? I don't have the master branch installed so I cant test here. |
Any further comments here? |
I'm still going to propose using different punctuation for the frame numbering, the use of square brackets for both REPL defined functions and frame numbering makes them look interrelated when they aren't. |
"Framing" the stackframe number with a |
Thinking about it more, I think keeping like this is fine. REPL frames will be color coded (bolded) in the terminal and will typically not exist outside interative use. Distinguishing them should not be a problem. If it gets annoying, could trivially be changed in another PR. |
@@ -737,7 +737,6 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 1:2:5) | |||
|
|||
julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2)) | |||
ERROR: ArgumentError: indices must be unique and sorted | |||
Stacktrace: |
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.
won't this be needed to pass the doctest?
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.
updated, I messed up with the online rebase tool
bold vs non bold doesn't add any context to where the repl square brackets are coming from. frame numbers are at least obviously ordered, and would look fine with almost any demarcation, pun notwithstanding. |
Ok. I've kinda run out of steam for this PR (and #18228) so if the potential confusion between REPL numbers and frame numbers is merge blocking, I might have another go at it for 1.0. |
I think it's fine, the REPL as |
Woot. I'm on standby for the fallout so ping away :) |
I'll submit a PR proposing to make the frame numbering (and add NEWS links back for #18453 (comment)) |
This PR tries to make it a bit easier to visually parse error messages that are printed in the REPL. It does this by no longer printing the stack trace in red, numbers each stack frame and makes the function name and file/line info bold since I believe they are often more interesting than the types the functions are being called it.
For a lot of background info and back and forth on design see #18228. Some more ambitious attempts were tried there but in the end I settled for something that is quite similar to what we have now.
Before and after pictures:
For a a future PR, the last stacktrace could be saved on error and the user can write the stack number, press a hotkey, and that file would be opened in the editor at the correct line.
This current PR fails on the Apple build because it inserts an extra space in the test at https://github.com/JuliaLang/julia/compare/kc/error_msgs_2?expand=1#diff-e44967823c8efd2b46505406ac7e9e7cR212. I have no idea why and can't really test it well since I don't have a mac.