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

It is impossible to catch Panics in the GUI #9402

Closed
radeusgd opened this issue Mar 13, 2024 · 7 comments · Fixed by #11167
Closed

It is impossible to catch Panics in the GUI #9402

radeusgd opened this issue Mar 13, 2024 · 7 comments · Fixed by #11167

Comments

@radeusgd
Copy link
Member

image

I would like to be able to catch a panic for example in order to inspect its stack trace.

Ideally, the visualization should allow to show a stack trace for a panic by default, but that's probably another thing.

Expected behaviour

The same operations in the REPL work and allow to catch a Panic:

Uncaught panic

> r = Panic.throw "foo"
null:: warning: Unused variable r.
Evaluation failed with: foo
java.lang.Exception: foo
        at <enso>.Panic.throw(Unknown Source)
        at <enso>.<eval>(Unknown Source)
        at <enso>.Debug.breakpoint(Unknown Source)
        at <enso>.Rrepl::Rrepl::main(Rrepl.enso:46)
        at <unknown>.org.graalvm.polyglot.Value<Function>.execute(Unknown Source)

> r
null:: error: The name `r` could not be found.
Evaluation failed with: Compilation aborted due to errors.
java.lang.Exception: Compilation aborted due to errors.
        at <enso>.Debug.breakpoint(Unknown Source)
        at <enso>.Rrepl::Rrepl::main(Rrepl.enso:46)
        at <unknown>.org.graalvm.polyglot.Value<Function>.execute(Unknown Source)

Panic recovered as dataflow error

> r = Panic.recover Any (Panic.throw "foo")
null:: warning: Unused variable r.
>>> Nothing
> r
>>> (Error: 'foo')
> r.catch
>>> foo

Caught panic

> r = Panic.catch Any (Panic.throw "foo") c->c.payload
null:: warning: Unused variable r.
>>> Nothing
> r
>>> foo
@radeusgd
Copy link
Member Author

Added a triage label because while the issue is showing up in the GUI, it likely may be an issue in the runtime.

@sylwiabr sylwiabr removed the triage label Mar 22, 2024
@4e6
Copy link
Contributor

4e6 commented Sep 19, 2024

I encountered this issue today. In the expression

Panic.catch Any (Panic.throw 42) _.payload
  • when the Panic.throw 42 sub-expression is instrumented, the Panic.catch expression is ignored and the whole expression results in a panic
  • when the Panic.throw 42 sub-expression is not instrumented, the whole expression results in 42 correctly

I created a test reproducing this issue on the wip/db/9402-catch-panic-instrumented branch

@4e6 4e6 added -compiler and removed -gui labels Sep 19, 2024
@4e6
Copy link
Contributor

4e6 commented Sep 19, 2024

The issue might be that we're unwinding too early

@JaroslavTulach JaroslavTulach self-assigned this Sep 24, 2024
@JaroslavTulach JaroslavTulach moved this from ❓New to 📤 Backlog in Issues Board Sep 24, 2024
@JaroslavTulach JaroslavTulach moved this from 📤 Backlog to ❓New in Issues Board Sep 24, 2024
@JaroslavTulach
Copy link
Member

The code runs fine from CLI. The project seems to work for me, when "booted". Only later it "diverges from regular run flow":

works

Yes, the problem is likely in the instrument.

@JaroslavTulach
Copy link
Member

The instrument converts PanicException to a sentinel and the catch node then ignores it. The following seems to help:

index 53a716f4fb..6d29469fad 100644
--- engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/CatchPanicNode.java
+++ engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/CatchPanicNode.java
@@ -20,6 +20,7 @@ import org.enso.interpreter.runtime.EnsoContext;
 import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo;
 import org.enso.interpreter.runtime.data.atom.AtomNewInstanceNode;
 import org.enso.interpreter.runtime.error.PanicException;
+import org.enso.interpreter.runtime.error.PanicSentinel;
 import org.enso.interpreter.runtime.state.State;
 
 @BuiltinMethod(
@@ -61,7 +62,11 @@ public abstract class CatchPanicNode extends Node {
       @CachedLibrary(limit = "3") InteropLibrary interop) {
     try {
       // Note [Tail call]
-      return thunkExecutorNode.executeThunk(frame, action, state, BaseNode.TailStatus.NOT_TAIL);
+      var ret = thunkExecutorNode.executeThunk(frame, action, state, BaseNode.TailStatus.NOT_TAIL);
+      if (ret instanceof PanicSentinel sentinel) {
+        throw sentinel.getPanic();
+      }
+      return ret;
     } catch (PanicException e) {
       panicBranchProfile.enter();
       Object payload = e.getPayload();

@JaroslavTulach JaroslavTulach moved this from 📤 Backlog to 👁️ Code review in Issues Board Sep 25, 2024
@mergify mergify bot closed this as completed in #11167 Sep 26, 2024
@mergify mergify bot closed this as completed in 2fbd0aa Sep 26, 2024
@github-project-automation github-project-automation bot moved this from 👁️ Code review to 🟢 Accepted in Issues Board Sep 26, 2024
@enso-bot
Copy link

enso-bot bot commented Sep 27, 2024

Jaroslav Tulach reports a new STANDUP for yesterday (2024-09-26):

Progress: .

@enso-bot
Copy link

enso-bot bot commented Sep 28, 2024

Jaroslav Tulach reports a new STANDUP for yesterday (2024-09-27):

Progress: .

Discord
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🟢 Accepted
Development

Successfully merging a pull request may close this issue.

4 participants