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

The library developer should be able to handle specific types of Panics while passing through others #3344

Merged
merged 28 commits into from
Mar 18, 2022

Conversation

radeusgd
Copy link
Member

@radeusgd radeusgd commented Mar 15, 2022

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:

  • The documentation has been updated if necessary.
  • All code conforms to the Scala, Java, and Rust style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH ./run dist and ./run watch.

@radeusgd radeusgd self-assigned this Mar 15, 2022
@radeusgd radeusgd force-pushed the wip/radeusgd/lib-panic-catch-181569176 branch from 3c7fc8d to 3ee235f Compare March 16, 2022 14:21
@radeusgd radeusgd marked this pull request as ready for review March 16, 2022 16:43
@radeusgd radeusgd requested a review from kustosz March 16, 2022 16:43
@radeusgd radeusgd force-pushed the wip/radeusgd/lib-panic-catch-181569176 branch 2 times, most recently from 9298355 to 94ecc27 Compare March 16, 2022 19:37
Copy link
Contributor

@kustosz kustosz left a 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
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. to be able to get the stacktrace of a raw Java exception, if you get it from somewhere.
  2. Because it is exactly used as an internal helper to make Caught_Panic able to have the stack_trace method.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. from where tho...
  2. in this case, mark it private and state that this is what it's used for

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. possibly from caught_panic.payload.cause (I know there we simply have caught_panic.stack_trace but the payload may be passed further down) or from catch_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.

Copy link
Contributor

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

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

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.

Copy link
Member Author

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.

public class ThrowPanicNode extends Node {
Stateful execute(Object _this, Object payload) {
throw new PanicException(payload, this);
public abstract class ThrowPanicNode extends Node {
Copy link
Contributor

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:

  1. A specialization that only triggers for Caught_Panic.
  2. A specialization that only triggers for isException.
  3. A fallback.

Use specialization guards to refactor this nicely.

@radeusgd radeusgd force-pushed the wip/radeusgd/lib-panic-catch-181569176 branch from cd6a3ae to 095f819 Compare March 17, 2022 20:48
@radeusgd radeusgd requested a review from kustosz March 18, 2022 12:34
Copy link
Contributor

@kustosz kustosz left a 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
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

@4e6 4e6 left a comment

Choose a reason for hiding this comment

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

Very cool stuff!

Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@radeusgd radeusgd force-pushed the wip/radeusgd/lib-panic-catch-181569176 branch from dbdd1f5 to b4c6bf0 Compare March 18, 2022 14:37
@radeusgd radeusgd requested a review from hubertp March 18, 2022 14:38
@radeusgd radeusgd added the CI: Ready to merge This PR is eligible for automatic merge label Mar 18, 2022
Copy link
Contributor

@hubertp hubertp left a 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`.");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit in wording

Suggested change
"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

Copy link
Member Author

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

Choose a reason for hiding this comment

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

nit

Suggested change
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)

Copy link
Member Author

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.

@mergify mergify bot merged commit cc73338 into develop Mar 18, 2022
@mergify mergify bot deleted the wip/radeusgd/lib-panic-catch-181569176 branch March 18, 2022 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants