-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
raise(Exception): Setup callstack on raise only if not already set. #4487
raise(Exception): Setup callstack on raise only if not already set. #4487
Conversation
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.
Since the exception is raised from the same context (the spec block), aren't the callstacks equivalent?
src/raise.cr
Outdated
# Raises the *exception*. | ||
# | ||
# Note that exception callstack will only be set if it's not already set. | ||
# It's useful for reraising of exceptions in `rescue` blocks. |
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 the doc could be simpler? Maybe:
Raises an
Exception
.This will set the exception's callstack if it hasn't been already. Re-raising a previously catched exception won't replace the callstack.
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 suppose that the article just fit here.
And thanks for rewording, will apply.
spec/std/raise_spec.cr
Outdated
new_ex.callstack.should eq(callstack_to_match) | ||
end | ||
|
||
it "should throw exception with new callstack if not already set" do |
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 it sets exception's callstack
and it should come before the spec that says it doesn't overwrite the callback
.
It's useful for reraising of exceptions in `rescue` blocks. As proposed by crystal-lang#4482 (comment). /cc @asterite, @straight-shoota.
b357676
to
82eb2d4
Compare
@ysbaddaden I believe that we should not depend in this example on the assumption that we get the same exception. |
Although you are right, this is absolutely superfluous |
…ion when it's rescued.
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.
Structs don't need clone because they are value types. And their equals method by default compares all fields. Please remove the struct reopening.
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.
The spec is also wrong. You should raise, rescue and re-raise in the spec. That's what we really want to happen.
Thanks, @asterite . Now it looks cleaner. |
Thank you! |
@ysbaddaden would you mind setting the "Next" milestone to PRs when you merge them? It makes it easier for us to write release notes afterwards :) |
Oh ok, will do now! |
It's useful for reraising of exceptions in
rescue
blocks.As proposed by #4482 (comment).
/cc @asterite, @straight-shoota.