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

Throwing an unhandled exception in Polyglot Java results in a null in the UI and no caught error message #5260

Closed
wdanilo opened this issue Feb 5, 2023 · 14 comments · Fixed by #5684 or #5794
Assignees
Labels
--bug Type: bug -compiler p-high Should be completed in the next sprint

Comments

@wdanilo
Copy link
Member

wdanilo commented Feb 5, 2023

This task is automatically imported from the old Task Issue Board and it was originally created by James Dunkerley.
Original issue is here.


Throwing a NPE within Java caused an error when command line:

Execution finished with an error: null
        at <java> org.enso.table.data.index.MultiValueIndex.makeCrossTabTable(MultiValueIndex.java:185)
        at <enso> case_branch(C:\Repos\Enso\ide\built-distribution\enso-engine-0.0.0-dev-windows-amd64\enso-0.0.0-dev\lib\Standard\Table\0.0.0-dev\src\Data\Table.enso:1299:21-122)

Within the UI get no error message and the viz shows null. Error from Language Server shown below.

Comments:

(James Dunkerley - Dec 20, 2022)


``` from Standard.Base import Panic polyglot java import java.lang.NullPointerException

main =
x = NullPointerException.new
Panic.throw x

Easily reproducible via cli

built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --no-ir-caches --run ~/work/repos/enso/test-cases/thrownpe.enso
Execution finished with an error: null
at Panic.throw(Internal)
at thrownpe.main(thrownpe.enso:6:5-17)


It's because NPEs message is null. (Hubert Plociniczak - Dec 20, 2022)
<hr />

@wdanilo wdanilo added this to the Beta Release milestone Feb 6, 2023
@jdunkerley jdunkerley added -compiler and removed -libs Libraries: New libraries to be implemented labels Feb 6, 2023
@jdunkerley jdunkerley moved this to ❓New in Issues Board Feb 7, 2023
@jdunkerley jdunkerley moved this from ❓New to 📤 Backlog in Issues Board Feb 7, 2023
@jdunkerley jdunkerley assigned JaroslavTulach and unassigned hubertp Feb 14, 2023
@JaroslavTulach
Copy link
Member

What exactly is the bug report? I see it is concerned with NullPointerException. However as of Feb 17, 2023 I see following behavior.

Visualizing NullPointerException

I can throw, Panic.catch and visualize NullPointerException - there are no null messages anymore anywhere:

Visualizing NPE

When running the same program from CLI I get:

java.lang.NullPointerException

which is correct in my opinion - again there is no null anywhere.

Panic with NullPointerException

Modifying the program to propagate the panic (e.g. main = thr) leads to following behavior in CLI:

$ enso --run .
Execution finished with an error: null
        at <enso> Panic.throw(Internal)
        at <enso> Main.thr(/home/devel/enso/projects/Unnamed/src/Main.enso:12:5-17)
        at <enso> Main.main(/home/devel/enso/projects/Unnamed/src/Main.enso:7:8-10)

e.g. yes, there is a null instead of NullPointerException. Doing the same in the IDE leads to an empty visualization:

Empty visualization

and following message being printed in project-manager console:

[warn] [enso] Execution of function main failed (class com.oracle.truffle.host.HostException).

@JaroslavTulach
Copy link
Member

With the #5684 fixes I see following message being delivered to the IDE. Regardless of that, there is no error indication:

image

I believe the real fix needs to be done on the IDE side. Somehow handle the executionContext/executionStatus with kind: "Error". Possibly displaying the message, if it is there (it will there for sure once #5684 gets integrated). I am asking for a new triage.

@vitvakatu
Copy link
Contributor

It seems IDE ignores executionStatus updates completely. @farmaazon please correct me if I'm wrong.

To display errors, we use information provided by ExpressionUpdate message. Why in this case the engine does not use it? What is the difference between an error provided by ExpressionUpdate and an error from executionStatus, @JaroslavTulach ?

@JaroslavTulach
Copy link
Member

The world of Enso errors is rich (compilation errors, values with warnings, errors and panics). The message above is result of a Panic.throw. I have no idea why it send the message it sends.

@farmaazon
Copy link
Contributor

It seems IDE ignores executionStatus updates completely. @farmaazon please correct me if I'm wrong.

Yes, that's true. The reason is (not sure if still valid) that the diagnostics are text-oriented, giving us line number instead of node id.

@mergify mergify bot closed this as completed in #5684 Feb 20, 2023
mergify bot pushed a commit that referenced this issue Feb 20, 2023
…tently (#5684)

Creating two `findExceptionMessage` methods in `HostEnsoUtils` and in `VisualizationResult`. Why two? Because one of them is using `org.graalvm.polyglot` SDK as it runs in _"normal Java"_ mode. The other one is using Truffle API as it is running inside of partially evaluated instrument.

There is a `FindExceptionMessageTest` to guarantee consistency between the two methods. It simulates some exceptions in Enso code and checks that both methods extract the same _"message"_ from the exception. The tests verifies hosted and well as Enso exceptions - however testing other polyglot languages is only possible in other modules - as such I created `PolyglotFindExceptionMessageTest` - but that one doesn't have access to Truffle API - e.g. it doesn't really check the consistency - just that a reasonable message is extracted from a JavaScript exception.

# Important Notes
This is not full fix of #5260 - something needs to be done on the IDE side, as the IDE seems to ignore the delivered JSON message - even if it contains properly extracted exception message.
@github-project-automation github-project-automation bot moved this from 📤 Backlog to 🟢 Accepted in Issues Board Feb 20, 2023
@JaroslavTulach
Copy link
Member

#5684 only makes sure the executionContext/executionStatus message is delivered. Now it is up to the IDE to tell the user (a message in status bar?) that such problem happened.

@github-project-automation github-project-automation bot moved this from 🟢 Accepted to ❓New in Issues Board Feb 20, 2023
@farmaazon
Copy link
Contributor

#5684 only makes sure the executionContext/executionStatus message is delivered. Now it is up to the IDE to tell the user (a message in status bar?) that such problem happened.

Of course, we can display the message in status bar somewhere, but it will be still inferior UX from just having a concrete node colored. Is the latter impossible to implement in the engine?

@jdunkerley jdunkerley removed the p-low Low priority label Feb 21, 2023
@jdunkerley jdunkerley added the p-high Should be completed in the next sprint label Feb 21, 2023
@jdunkerley jdunkerley removed the triage label Feb 21, 2023
@farmaazon
Copy link
Contributor

I don't think this should be assigned to me. As I wrote, the panics should be reported in values update payload, so we can display them on nodes. Displaying global execution problems deserves its own task and will be done after we implement messages for the user. However, it does not fix the problem reported by this issue: reporting things in executionStatus should not be a normal routine.

@JaroslavTulach Please answer my question: isn't fixing the problem correctly (by sending Panic payload) impossible in the engine?

Cc @wdanilo @xvcgreg

@jdunkerley jdunkerley added -compiler and removed -gui labels Feb 21, 2023
@jdunkerley jdunkerley moved this from ❓New to 📤 Backlog in Issues Board Feb 21, 2023
@wdanilo
Copy link
Member Author

wdanilo commented Feb 21, 2023

CC @sylwiabr as she took over planning from Greg

@JaroslavTulach
Copy link
Member

Of course, we can display the message in status bar somewhere,

That would, in my opinion, be a great start, @farmaazon. Just use the information you have - executionContext/executionStatus. It's likely an hour long fix, right? If so, I'd start with that, fix the current state (when the information is completely missing) and then ...

but it will be still inferior UX from just having a concrete node colored. Is the latter impossible to implement in the engine?

... I would report a feature request to improve the UX by changing the protocol API.

... (by sending Panic payload) ...

In any case, I'd like you to show/propose/demonstate the requeted API changes by modifying language server specification. I am not completely sure what "by sending Panic payload" means in terms of language server protocol...

@farmaazon
Copy link
Contributor

That would, in my opinion, be a great start, @farmaazon. Just use the information you have - executionContext/executionStatus. It's likely an hour long fix, right? If so, I'd start with that, fix the current state (when the information is completely missing) and then ...

Not so fast, we don't have a way to display long messages to the user yet. It's part of #5201 - definitely not an hour of work.

In any case, I'd like you to show/propose/demonstate the requeted API changes by modifying language server specification. I am not completely sure what "by sending Panic payload" means in terms of language server protocol...

I don't need to change API, because we already have an API for reporting panics. Citing the protocol specification:

type ExpressionUpdatePayload = Value | DatafalowError | Panic | Pending;

/* ... */

/**
 * Indicates that the expression failed with the runtime exception.
 */
interface Panic {
  /**
   * The error message.
   */
  message: String;

  /**
   * The stack trace.
   */
  trace: ExpressionId[];
}

If you don't send Panic payload when a runtime error occurs, then you don't comply to the API. If you send null or empty string in message string, then you also don't comply to the API, which clearly states that this should be an error message.

@JaroslavTulach
Copy link
Member

Not so fast, we don't have a way to display long messages to the user yet. It's part of #5201 - definitely not an hour of work.

We don't need a full blown solution right now:

would be enough to fix the most painful problem

I don't need to change API, because we already have an API for reporting panics. Citing ...

OK. Thank you for the explanation and showing me the missing piece of the puzzle.

@farmaazon
Copy link
Contributor

We don't need a full blown solution right now:

This partial solution has serious drawbacks, I described in the PR. But even with the perfect implementation with all diagnostics displayed in a neat multiline notification will be inferior to have this exception reported as Panic, with nice node coloring and proper propagation through the graph (so the user will quickly find it if it's in a nested function).

I've checked what we receive in IDE. First, I created such a graph, where a panic is indeed properly reported, even with the polyglot type (the message, however, is a bit of obscure for user not accustomed to java):

Image

The issue appears when I want to throw an exception instance:

Image

The only expressionUpdate message I receive is:

{"jsonrpc":"2.0","method":"executionContext/expressionUpdates","params":{"contextId":"8ddbdd9b-c01b-4084-94b3-df9d66f82d55","updates":[{"expressionId":"4c563f3b-0bb1-4524-947d-12c68cb6010d","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"7e5e1bce-8a85-4e3e-91a8-69064a78e806","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"19d1c03f-4799-4acf-9108-33d8024aa4ec","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"a40fb8ad-11e3-45c2-940e-ad1331b3665a","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"007ea7f6-1739-4ba6-bd05-97baeabca0ed","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"c8261625-f4cb-4afc-9b0d-99fddc7198a6","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"238845ae-e890-4f4b-8b6b-53d29142cd1d","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"2ca22482-e25c-4e4b-a080-46744c848208","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"8dd29e9a-a5fc-407d-9275-c95b0853ebe8","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"29e20c13-7e9a-4a09-92e9-03484de53bbc","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"ce8aa384-d43c-4853-a234-a6a993938d6d","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"19d1c03f-4799-4acf-9108-33d8024aa4ec","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"0818b28f-46a9-4d9c-9eea-cc0d175d36fc","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"129b1d1c-3e27-43ac-a0e4-32dbb428be59","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"bcd222bd-1194-484b-b2e3-0558feec8dbb","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"7e5e1bce-8a85-4e3e-91a8-69064a78e806","type":null,"methodPointer":null,"profilingInfo":[],"fromCache":true,"payload":{"type":"Pending","message":null,"progress":null}},{"expressionId":"8dd29e9a-a5fc-407d-9275-c95b0853ebe8","type":"Standard.Builtins.Main.Unresolved_Symbol","methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":3280}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"0818b28f-46a9-4d9c-9eea-cc0d175d36fc","type":null,"methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":2559}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"ce8aa384-d43c-4853-a234-a6a993938d6d","type":null,"methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":1196376}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"29e20c13-7e9a-4a09-92e9-03484de53bbc","type":"Standard.Base.Nothing.Nothing","methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":1656200}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"238845ae-e890-4f4b-8b6b-53d29142cd1d","type":"Standard.Builtins.Main.Unresolved_Symbol","methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":2564}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"c8261625-f4cb-4afc-9b0d-99fddc7198a6","type":"Standard.Base.Panic.Panic.type","methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":1929}}],"fromCache":false,"payload":{"type":"Value","warnings":null}},{"expressionId":"bcd222bd-1194-484b-b2e3-0558feec8dbb","type":null,"methodPointer":null,"profilingInfo":[{"ExecutionTime":{"nanoTime":41173}}],"fromCache":false,"payload":{"type":"Value","warnings":null}}]}}

As you see, no panic payload is reported, only panic type. Moreover, there are "pending" expressions which seem to be never computed (I did not receive any further expressionUpdate).

So, the proper solution for this issue is fixing Panic sending (those never ending pending expressions also deserves fixing).

@farmaazon farmaazon removed their assignment Feb 23, 2023
@farmaazon farmaazon removed the -gui label Feb 23, 2023
@jdunkerley jdunkerley moved this from 📤 Backlog to 👁️ Code review in Issues Board Feb 28, 2023
@jdunkerley jdunkerley moved this from 👁️ Code review to 🔧 Implementation in Issues Board Feb 28, 2023
@mergify mergify bot closed this as completed in #5794 Mar 6, 2023
mergify bot pushed a commit that referenced this issue Mar 6, 2023
Report `AbstractTruffleException` as a `Panic`. Fixes #5260.
@github-project-automation github-project-automation bot moved this from 🔧 Implementation to 🟢 Accepted in Issues Board Mar 6, 2023
@enso-bot
Copy link

enso-bot bot commented Mar 7, 2023

Jaroslav Tulach reports a new STANDUP for yesterday (2023-03-06):

Progress: - Report AbstractTruffleException as a Panic: merged #5794

Next Day: #5177 + Performance & stability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment