Skip to content

Commit

Permalink
Include Ruby exception message in VM interleaving error
Browse files Browse the repository at this point in the history
This would help debugging the nested VM operation error.
  • Loading branch information
kateinoigakukun committed Mar 16, 2024
1 parent aee363b commit 4b53900
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit 4b53900

Please sign in to comment.