Skip to content

[wasm] fix missing managed stack trace on managed exceptions marshaled to JS #75678

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

Merged
merged 6 commits into from
Sep 17, 2022

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Sep 15, 2022

When we display managed exception marshaled to JS as ManagedError via toString we only print:

ManagedError(gc_handle: 214)

The fix makes it to print both managed and JS stack trace

     at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.ThrowFromJSExport(String message) in JavaScriptTestHelper.cs:line 41
     at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.__Wrapper_ThrowFromJSExport_849163347(JSMarshalerArgument* __arguments_buffer) in JSExports.g.cs:line 50
  Error: -t-e-s-t-
      at marshal_exception_to_js (dotnet.js:2803:22)
      at invoke_method_and_handle_exception (dotnet.js:5030:19)
      at bound_fn_1R (dotnet.js:4964:17)
      at Module.catch1toString (JavaScriptTestHelper.mjs:117:9)
      at bound_fn_2R (dotnet.js:4696:35)
      at Object.mono_wasm_invoke_import (dotnet.js:4747:9)
      at _mono_wasm_invoke_import (dotnet.js:16384:82)
      at do_icall (do_icall (wasm://wasm/02e6dfee:wasm-function[308]:0x1dbed))
      at do_icall_wrapper (do_icall_wrapper (wasm://wasm/02e6dfee:wasm-function[285]:0x1cd26))
      at interp_exec_method (interp_exec_method (wasm://wasm/02e6dfee:wasm-function[235]:0xc4ca))
      at interp_runtime_invoke (interp_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[234]:0xb1bd))
      at mono_jit_runtime_invoke (mono_jit_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[15606]:0x27f8d3))
      at do_runtime_invoke (do_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3302]:0xe9376))
      at mono_runtime_invoke_checked (mono_runtime_invoke_checked (wasm://wasm/02e6dfee:wasm-function[3300]:0xe9251))
      at mono_runtime_try_invoke_span (mono_runtime_try_invoke_span (wasm://wasm/02e6dfee:wasm-function[3449]:0xf1d9d))
      at mono_runtime_invoke_span_checked (mono_runtime_invoke_span_checked (wasm://wasm/02e6dfee:wasm-function[3450]:0xf21b8))
      at ves_icall_InternalInvoke (ves_icall_InternalInvoke (wasm://wasm/02e6dfee:wasm-function[1974]:0xa0a88))
      at ves_icall_InternalInvoke_raw (ves_icall_InternalInvoke_raw (wasm://wasm/02e6dfee:wasm-function[2197]:0xaeca0))
      at do_icall (do_icall (wasm://wasm/02e6dfee:wasm-function[308]:0x1dc71))
      at do_icall_wrapper (do_icall_wrapper (wasm://wasm/02e6dfee:wasm-function[285]:0x1cd26))
      at interp_exec_method (interp_exec_method (wasm://wasm/02e6dfee:wasm-function[235]:0xc4ca))
      at interp_runtime_invoke (interp_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[234]:0xb1bd))
      at mono_jit_runtime_invoke (mono_jit_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[15606]:0x27f8d3))
      at do_runtime_invoke (do_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3302]:0xe9376))
      at mono_runtime_try_invoke (mono_runtime_try_invoke (wasm://wasm/02e6dfee:wasm-function[3316]:0xea048))
      at mono_runtime_invoke (mono_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3382]:0xee01d))
      at mono_wasm_invoke_method_bound (mono_wasm_invoke_method_bound (wasm://wasm/02e6dfee:wasm-function[129]:0x8efa))
      at Module._mono_wasm_invoke_method_bound [as mono_wasm_invoke_method_bound] (dotnet.js:17161:149)
      at invoke_method_and_handle_exception (dotnet.js:5025:42)
      at runtimeHelpers.javaScriptExports.complete_task (dotnet.js:5185:17)
      at dotnet.js:3206:46

@pavelsavara pavelsavara added this to the 8.0.0 milestone Sep 15, 2022
@pavelsavara pavelsavara requested review from kg and maraf September 15, 2022 14:14
@pavelsavara pavelsavara self-assigned this Sep 15, 2022
@ghost
Copy link

ghost commented Sep 15, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

When we display managed exception marshaled to JS as ManagedError via toString we only print:

ManagedError(gc_handle: 214)

The fix makes use to print both managed and JS stack trace

System.ArgumentException: -t-e-s-t-
     at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.ThrowFromJSExport(String message) in JavaScriptTestHelper.cs:line 41
     at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.__Wrapper_ThrowFromJSExport_849163347(JSMarshalerArgument* __arguments_buffer) in JSExports.g.cs:line 50
  Error: -t-e-s-t-
      at marshal_exception_to_js (dotnet.js:2803:22)
      at invoke_method_and_handle_exception (dotnet.js:5030:19)
      at bound_fn_1R (dotnet.js:4964:17)
      at Module.catch1toString (JavaScriptTestHelper.mjs:117:9)
      at bound_fn_2R (dotnet.js:4696:35)
      at Object.mono_wasm_invoke_import (dotnet.js:4747:9)
      at _mono_wasm_invoke_import (dotnet.js:16384:82)
      at do_icall (do_icall (wasm://wasm/02e6dfee:wasm-function[308]:0x1dbed))
      at do_icall_wrapper (do_icall_wrapper (wasm://wasm/02e6dfee:wasm-function[285]:0x1cd26))
      at interp_exec_method (interp_exec_method (wasm://wasm/02e6dfee:wasm-function[235]:0xc4ca))
      at interp_runtime_invoke (interp_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[234]:0xb1bd))
      at mono_jit_runtime_invoke (mono_jit_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[15606]:0x27f8d3))
      at do_runtime_invoke (do_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3302]:0xe9376))
      at mono_runtime_invoke_checked (mono_runtime_invoke_checked (wasm://wasm/02e6dfee:wasm-function[3300]:0xe9251))
      at mono_runtime_try_invoke_span (mono_runtime_try_invoke_span (wasm://wasm/02e6dfee:wasm-function[3449]:0xf1d9d))
      at mono_runtime_invoke_span_checked (mono_runtime_invoke_span_checked (wasm://wasm/02e6dfee:wasm-function[3450]:0xf21b8))
      at ves_icall_InternalInvoke (ves_icall_InternalInvoke (wasm://wasm/02e6dfee:wasm-function[1974]:0xa0a88))
      at ves_icall_InternalInvoke_raw (ves_icall_InternalInvoke_raw (wasm://wasm/02e6dfee:wasm-function[2197]:0xaeca0))
      at do_icall (do_icall (wasm://wasm/02e6dfee:wasm-function[308]:0x1dc71))
      at do_icall_wrapper (do_icall_wrapper (wasm://wasm/02e6dfee:wasm-function[285]:0x1cd26))
      at interp_exec_method (interp_exec_method (wasm://wasm/02e6dfee:wasm-function[235]:0xc4ca))
      at interp_runtime_invoke (interp_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[234]:0xb1bd))
      at mono_jit_runtime_invoke (mono_jit_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[15606]:0x27f8d3))
      at do_runtime_invoke (do_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3302]:0xe9376))
      at mono_runtime_try_invoke (mono_runtime_try_invoke (wasm://wasm/02e6dfee:wasm-function[3316]:0xea048))
      at mono_runtime_invoke (mono_runtime_invoke (wasm://wasm/02e6dfee:wasm-function[3382]:0xee01d))
      at mono_wasm_invoke_method_bound (mono_wasm_invoke_method_bound (wasm://wasm/02e6dfee:wasm-function[129]:0x8efa))
      at Module._mono_wasm_invoke_method_bound [as mono_wasm_invoke_method_bound] (dotnet.js:17161:149)
      at invoke_method_and_handle_exception (dotnet.js:5025:42)
      at runtimeHelpers.javaScriptExports.complete_task (dotnet.js:5185:17)
      at dotnet.js:3206:46
Author: pavelsavara
Assignees: pavelsavara
Labels:

arch-wasm, area-System.Runtime.InteropServices.JavaScript

Milestone: 8.0.0

@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara

This comment was marked as outdated.

@pavelsavara pavelsavara marked this pull request as ready for review September 15, 2022 16:45
@pavelsavara pavelsavara requested a review from lewing as a code owner September 15, 2022 16:45
@lewing lewing requested a review from thaystg September 15, 2022 16:57
Copy link
Member

@kg kg left a comment

Choose a reason for hiding this comment

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

Looks fine other than the ManagedError inheritance question and toString

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 15, 2022
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 16, 2022
@pavelsavara
Copy link
Member Author

/azp run runtime-wasm

@pavelsavara pavelsavara requested a review from kg September 16, 2022 16:32
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pavelsavara pavelsavara merged commit 7144b28 into dotnet:main Sep 17, 2022
@pavelsavara
Copy link
Member Author

/backport to release/7.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/7.0-rc2: https://github.com/dotnet/runtime/actions/runs/3073338553

@github-actions
Copy link
Contributor

@pavelsavara backporting to release/7.0-rc2 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: fix missing managed stack trace on managed exceptions marshaled to JS
Using index info to reconstruct a base tree...
M	src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
M	src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs
M	src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs
M	src/mono/wasm/runtime/marshal-to-js.ts
M	src/mono/wasm/runtime/marshal.ts
M	src/mono/wasm/runtime/run.ts
M	src/mono/wasm/runtime/types.ts
Falling back to patching base and 3-way merge...
Auto-merging src/mono/wasm/runtime/types.ts
Auto-merging src/mono/wasm/runtime/run.ts
CONFLICT (content): Merge conflict in src/mono/wasm/runtime/run.ts
Auto-merging src/mono/wasm/runtime/marshal.ts
Auto-merging src/mono/wasm/runtime/marshal-to-js.ts
Auto-merging src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs
Auto-merging src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs
Auto-merging src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 fix missing managed stack trace on managed exceptions marshaled to JS
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@pavelsavara pavelsavara deleted the wasm_js_stack_trace branch October 13, 2022 10:04
@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants