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

Display of exception stacks could be better #31257

Closed
fredrikekre opened this issue Mar 5, 2019 · 1 comment · Fixed by #36606
Closed

Display of exception stacks could be better #31257

fredrikekre opened this issue Mar 5, 2019 · 1 comment · Fixed by #36606
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error handling Handling of exceptions by Julia or the user

Comments

@fredrikekre
Copy link
Member

fredrikekre commented Mar 5, 2019

To me the new exception stack printing (#30900) is not so clear, compare with e.g. this reduced example:

$ cat foo.jl 
function foo()
    error("hello")
end
foo()

which displays on master as

$ julia-master --color=yes foo.jl 
ERROR: Error while loading expression starting at /home/fredrik/foo.jl:4
caused by [exception 1]
hello
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [...]
 [8] _start() at ./client.jl:476

and on Julia 1 as

$ julia11 --color=yes foo.jl 
ERROR: LoadError: hello
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [...]
 [8] _start() at ./client.jl:436
in expression starting at /home/fredrik/foo.jl:4

I have two problems with the new printing:

  1. From the output on master it took me quite a while to understand that the hello output actually came from the ERROR: two lines above. IMO it was more clear before what the error was, and I suggest this should be printed as

    $ julia-master --color=yes foo.jl 
    ERROR: hello
    while loading expression starting at /home/fredrik/foo.jl:4
    caused by [exception 1]
    Stacktrace:
     [1] error(::String) at ./error.jl:33
     [...]
     [8] _start() at ./client.jl:476
    

    instead. It seems more important to print the message before the location.

  2. When seeing caused by [exception 1] I would expect a list of exceptions somewhere where I can look up what exception 1 is. What is exception 1 in the case above? It is not clear to me.

@fredrikekre fredrikekre added domain:error handling Handling of exceptions by Julia or the user domain:display and printing Aesthetics and correctness of printed representations of objects. labels Mar 5, 2019
@JeffBezanson
Copy link
Sponsor Member

What's happening is that there are two errors; the original error("hello") which is the root cause, and a LoadError thrown because of that. So what it's trying to say is "a LoadError happened at this file location, caused by the error hello". So hello needs to somehow be after "caused by". That allows it to chain sensibly in the general case, e.g.

julia> try
       try
       error(1)
       catch
       error(2)
       end
       catch
       error(3)
       end
ERROR: 3
Stacktrace:
 [1] error(::Int64) at ./error.jl:42
 [2] top-level scope at REPL[10]:8
caused by [exception 2]
2
Stacktrace:
 [1] error(::Int64) at ./error.jl:42
 [2] top-level scope at REPL[10]:5
caused by [exception 1]
1
Stacktrace:
 [1] error(::Int64) at ./error.jl:42
 [2] top-level scope at REPL[10]:3

I agree [exception 1] is not too helpful though.

One possibility is to just remove LoadError, since I believe all the info should be in the stack trace now. Part of the problem is that it's not intuitive that a nested exception would be happening here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error handling Handling of exceptions by Julia or the user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants