-
-
Couldn't load subscription status.
- Fork 5.7k
Hide loading internals in LoadError / precompilation errors #55816
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
base: master
Are you sure you want to change the base?
Hide loading internals in LoadError / precompilation errors #55816
Conversation
|
Fixes #50161? |
| !isa(ex.error, LoadError) && print(io, "LoadError: ") | ||
| if bt isa StackTraces.StackTrace | ||
| # Remove the internals of how precompilation is set up | ||
| StackTraces.remove_frames!(bt, :include_package_for_output; reverse=true, n=1) |
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 a bit error-prone - in particular, doesn't it require ruling out recursion in the loading code?
I wonder if rethrow(truncate_bt=true) / throw(e; truncate_bt=true) or Base.truncate_catch_backtrace(...) or a similar functionality would be better behaved
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.
Yeah I guess the most certain part of this PR is what the result should look like. How that's achieved I was less clear on a good design.
What would be a good test case for recursion?
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.
@topolarity if you had a particular loading pattern in mind it'd be great to understand it better.
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.
By recursion do you mean an included file that has an include in it?
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.
Bump
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.
Sorry for the delay here @IanButterworth, I've been sitting on some changes to our stack trace handling that I wanted to upstream so that we can do this properly (without scanning for function names, etc.)
Let me get those open and come back to this early next week 🙂
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.
Perfect. Thanks
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.
@topolarity I was thinking about getting this in for 1.12. Did that work get completed?
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.
Just to document what I was thinking from the hackathon. I'd like to try this pattern out:
# in loading code...
struct UserCodeError
err::Any
backtrace_size::UInt
end
function foo()
try
unreliable_user_code()
catch err
# Save the backtrace size so that we can trim any "internal" frames that
# are added later.
rethrow(UserCodeError(err, length(Core.raw_catch_backtrace())))
end
end
function loading_entrypoint()
try
# ... (some code that directly / indirectly calls foo()
catch err
if err isa UserCodeError
# Restore the backtrace to its state when returning from the user code
# (i.e. remove any frames between `foo()` to `loading_entrypoint()`)
resize!(Core.raw_catch_backtrace(), err.backtrace_size)
# Forward the error to the user
rethrow(err.err)
else
rethrow(err)
end
end
endLet me know if you have any thoughts 👍
|
An alternative could be just to delete In general I don't love |
Fixes #50161
Related to #52988
With an error injected into the top level in Dates, and showing the effect deep in LazyArtifacts
This PR
Master