-
Notifications
You must be signed in to change notification settings - Fork 323
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
The library developer should be able to handle specific types of Panics while passing through others #3344
Conversation
...runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowPanicNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoSourceSection.java
Outdated
Show resolved
Hide resolved
3c7fc8d
to
3ee235f
Compare
9298355
to
94ecc27
Compare
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 like this, but I don't like some of this 😁
Panic.get_attached_stack_trace error = | ||
throwable = case error of | ||
Caught_Panic _ internal_original_exception -> internal_original_exception | ||
throwable -> throwable |
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.
Why does this exist? If I'm reading your code correctly, there's no way to interact with panics other than through CaughtPanic
?
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.
- to be able to get the stacktrace of a raw Java exception, if you get it from somewhere.
- Because it is exactly used as an internal helper to make
Caught_Panic
able to have thestack_trace
method.
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.
- from where tho...
- in this case, mark it private and state that this is what it's used for
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.
- possibly from
caught_panic.payload.cause
(I know there we simply havecaught_panic.stack_trace
but thepayload
may be passed further down) or fromcatch_java_exception
unless we decide to remove this function (but it's not clear yet). I just feel like that function may have its uses somewhere.
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.
OK, I'll believe you
distribution/lib/Standard/Base/0.0.0-dev/src/Error/Extensions.enso
Outdated
Show resolved
Hide resolved
IO.println "Caught an `Illegal_Argument_Error`: "+error.payload.message | ||
"fallback value" | ||
Panic.catch : Any -> Any -> (Caught_Panic -> Any) -> Any | ||
Panic.catch typ ~action handler = |
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.
Change it to exception_type
or sth. Why scare IDE users.
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.
Changed to panic_type
as I guess more consistent with our nomenclature.
distribution/lib/Standard/Base/0.0.0-dev/src/Error/Extensions.enso
Outdated
Show resolved
Hide resolved
...runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/CatchPanicNode.java
Show resolved
Hide resolved
...runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/CatchPanicNode.java
Outdated
Show resolved
Hide resolved
...runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowPanicNode.java
Outdated
Show resolved
Hide resolved
public class ThrowPanicNode extends Node { | ||
Stateful execute(Object _this, Object payload) { | ||
throw new PanicException(payload, this); | ||
public abstract class ThrowPanicNode extends Node { |
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 is an annoying mix of specializations and (unprofiled) inline typechecks. What I want this to be is:
- A specialization that only triggers for
Caught_Panic
. - A specialization that only triggers for
isException
. - A fallback.
Use specialization guards to refactor this nicely.
cd6a3ae
to
095f819
Compare
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.
Jest piękny, it's beautiful
Panic.get_attached_stack_trace error = | ||
throwable = case error of | ||
Caught_Panic _ internal_original_exception -> internal_original_exception | ||
throwable -> throwable |
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.
OK, I'll believe you
if (interopLibrary.isException(originalException)) { | ||
try { | ||
throw interopLibrary.throwException(originalException); | ||
} catch (UnsupportedMessageException e) { |
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.
please blow up with IllegalStateException
– we shouldn't want something that deeply broken to "kinda work" – I'd rather we inform people that this is a bug.
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.
Very cool stuff!
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.
LGTM 👍
Fix dataflow errors lacking stacktraces and some other issues
dbdd1f5
to
b4c6bf0
Compare
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.
nit picking, feel free to ignore
throw interopLibrary.throwException(originalException); | ||
} catch (UnsupportedMessageException e) { | ||
throw new IllegalStateException( | ||
"Impossible, `isException` returned true for `originalException`."); |
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.
nit in wording
"Impossible, `isException` returned true for `originalException`."); | |
"Unexpected true `isException` condition for `originalException`"); |
If something is impossible then there is no way it happens :)
But I noticed this being used in other places so feel free to ignore.
Also notice that sometimes exceptions end with a dot and sometimes not. My preference is for the latter but as long as things are consistent, idc
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.
Hmmm, fair point. Well I guess the idea is that it is 'impossible under the assumption that the functions we use abide by their contracts'.
Maybe worth considering rephrasing but as you pointed out - it is used for many places, so I'd prefer to be consistent - we may change all of them in some separate PR though if we agree that different phrasing would be better. On the other hand, if the condition indeed is impossible it may not be worth caring about it too much 😅
Handling a panic for a panicking action. | ||
## PRIVATE | ||
|
||
Returns a raw representation of the stack trace attached to the provided |
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.
nit
Returns a raw representation of the stack trace attached to the provided | |
Returns a raw representation of the stacktrace attached to the provided |
Either works as long as we are consistent (we don't seem to be)
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.
Fair point! Unfortunately I was off for the day and merge-bot already did its job - but yeah that would probably require going through the codebase and making it consistent - next time we are touching these areas I will try to remember to maybe do this change, as indeed consistency would be good.
Pull Request Description
Implements https://www.pivotaltracker.com/story/show/181569176
Also ensures that Dataflow Errors have proper stack traces (earlier they did not point at the right location).
Important Notes
Checklist
Please include the following checklist in your PR:
./run dist
and./run watch
.