Skip to content
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

Merged
merged 7 commits into from
Dec 29, 2016
Merged

Conversation

KristofferC
Copy link
Member

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:

image

image

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.

n_frames = 0
frame_counter = 0
process_backtrace((a,b) -> n_frames += 1, t)
n_frames != 0 && print(io, "\n\nStacktrace:")
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@tkelman
Copy link
Contributor

tkelman commented Dec 12, 2016

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?

@kshyatt kshyatt added error handling Handling of exceptions by Julia or the user REPL Julia's REPL (Read Eval Print Loop) labels Dec 12, 2016
@StefanKarpinski
Copy link
Member

I think they're visually different enough here to be clear.

@StefanKarpinski
Copy link
Member

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.

@MichaelHatherly
Copy link
Member

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.

@KristofferC
Copy link
Member Author

I'm having some troubles with the doctests. For example:

!! Test error in the following code block in 'docs/helpdb/Base.jl':

        julia> convert(Int, 3.0)
        3
        
        julia> convert(Int, 3.5)
        ERROR: InexactError()
        Stacktrace
         [1] convert(::Type{Int64}, ::Float64) at ./float.jl:656

    in expression:

        convert(Int, 3.5)

    expected:

        ERROR: InexactError()
        Stacktrace
         [1] convert(::Type{Int64}, ::Float64) at ./float.jl:656

    returned:

        ERROR: InexactError()
        Stacktrace:
         [1] convert(::Type{Int64}, ::Float64) at ./float.jl:656

I can't see any difference between them. Is it whitespace sensitive or?

@MichaelHatherly
Copy link
Member

Missing : after Stacktrace, but yes having a visual diff would be really nice.

@KristofferC
Copy link
Member Author

How could I not notice!? I looked at it for like a minute...

@MichaelHatherly
Copy link
Member

How could I not notice!? I looked at it for like a minute...

I just have plenty of practise reading that kind of output... really needs to be improved though.

@KristofferC
Copy link
Member Author

Tests pass, ready for a second, third etc. set of eyes.

@tkelman
Copy link
Contributor

tkelman commented Dec 13, 2016

Do the tests pass when color is disabled? Are the env vars documented anywhere?

@KristofferC
Copy link
Member Author

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.

@StefanKarpinski
Copy link
Member

I'm fine with using environment variables as an interim thing, but we need a better approach.

@KristofferC
Copy link
Member Author

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.

@cossio
Copy link
Contributor

cossio commented Dec 14, 2016

Could this be extended to errors in scripts (outside REPL) too?

@KristofferC
Copy link
Member Author

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.

@cossio
Copy link
Contributor

cossio commented Dec 14, 2016

@KristofferC Actually, I meant scripts outside the REPL, run from the shell, like:

$ julia myscript.jl

@KristofferC
Copy link
Member Author

Ah, I see. I am not sure where the error is actually thrown from in that case. Maybe from the c code?

@KristofferC
Copy link
Member Author

Rebased. AV failure is in pkg with some network problems.

@KristofferC
Copy link
Member Author

KristofferC commented Dec 21, 2016

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 (jl_throw and friends) but didn't really understand exactly where the backtrace is being printed and what julia functions are being called from that point. Guidance appreciated.

@yuyichao
Copy link
Contributor

All errors are thrown by C code and all exceptions with backtraces are printed in julia code by showerror. Crash backtraces are printed by jl_gdblookup.

@KristofferC
Copy link
Member Author

KristofferC commented Dec 21, 2016

@cossio I am a bit confused because this does already seems to work when running files from the shell, i.e.

➜  julia git:(kc/error_msgs_2) ✗ ./julia err.jl
ERROR: LoadError: Erp

Stacktrace:
 [1] error(::String) at ./error.jl:21
 [2] include_from_node1(::String) at ./loading.jl:532
 [3] include(::String) at ./sysimg.jl:14
 [4] process_options(::Base.JLOptions) at ./client.jl:275
 [5] _start() at ./client.jl:339
while loading /home/kristoffer/julia/err.jl, in expression starting on line 2

@cossio
Copy link
Contributor

cossio commented Dec 22, 2016

@KristofferC will it be colored as well? I don't have the master branch installed so I cant test here.

@KristofferC
Copy link
Member Author

It should now

image

I completely removed the hascolor symbol from the IOContext and just went with the global variable have_color that is normally used for colored output. Not sure why I didn't do like that in the first place.

@KristofferC
Copy link
Member Author

Any further comments here?

@tkelman
Copy link
Contributor

tkelman commented Dec 23, 2016

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.

@KristofferC
Copy link
Member Author

"Framing" the stackframe number with a [] makes too much sense to change. Could change the way REPL filename is printed?

@KristofferC
Copy link
Member Author

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:
Copy link
Contributor

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?

Copy link
Member Author

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

@tkelman
Copy link
Contributor

tkelman commented Dec 28, 2016

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.

@KristofferC
Copy link
Member Author

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.

@Keno
Copy link
Member

Keno commented Dec 28, 2016

I think it's fine, the REPL as REPL prominently written next to it. If it turns out to be a problem we can revisit. Thanks for all your hard work on this!

@KristofferC KristofferC added this to the 0.6.0 milestone Dec 29, 2016
@StefanKarpinski StefanKarpinski merged commit dc7b4fb into master Dec 29, 2016
@KristofferC
Copy link
Member Author

Woot. I'm on standby for the fallout so ping away :)

@tkelman
Copy link
Contributor

tkelman commented Dec 29, 2016

I'll submit a PR proposing to make the frame numbering 1. etc

(and add NEWS links back for #18453 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants