Skip to content

Include Ruby exception message in VM interleaving error #411

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 1 commit into from
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/npm-packages/ruby-wasm-wasi/src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export class RubyVM {
const str = new TextDecoder().decode(
new Uint8Array(memory.buffer, messagePtr, messageLen),
);
throw new RbFatalError(
"Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
let message = "Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
`(${str})\n` +
"Nested VM operation means that the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby " +
"caused by something like `window.rubyVM.eval(\"JS.global[:rubyVM].eval('Fiber.yield')\")`\n" +
Expand All @@ -148,8 +147,13 @@ export class RubyVM {
" Note that `evalAsync` JS API switches fibers internally\n" +
" 2. Raising uncaught exceptions\n" +
" Please catch all exceptions inside the nested operation\n" +
" 3. Calling Continuation APIs\n",
);
" 3. Calling Continuation APIs\n";

const error = new RbValue(this.guest.rbErrinfo(), this, this.privateObject());
if (error.call("nil?").toString() === "false") {
message += "\n" + this.exceptionFormatter.format(error, this, this.privateObject());
}
throw new RbFatalError(message);
},
};
// NOTE: The GC may collect objects that are still referenced by Wasm
Expand Down