Skip to content

Commit 4b53900

Browse files
Include Ruby exception message in VM interleaving error
This would help debugging the nested VM operation error.
1 parent aee363b commit 4b53900

File tree

1 file changed

+8
-4
lines changed
  • packages/npm-packages/ruby-wasm-wasi/src

1 file changed

+8
-4
lines changed

packages/npm-packages/ruby-wasm-wasi/src/vm.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export class RubyVM {
137137
const str = new TextDecoder().decode(
138138
new Uint8Array(memory.buffer, messagePtr, messageLen),
139139
);
140-
throw new RbFatalError(
141-
"Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
140+
let message = "Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
142141
`(${str})\n` +
143142
"Nested VM operation means that the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby " +
144143
"caused by something like `window.rubyVM.eval(\"JS.global[:rubyVM].eval('Fiber.yield')\")`\n" +
@@ -148,8 +147,13 @@ export class RubyVM {
148147
" Note that `evalAsync` JS API switches fibers internally\n" +
149148
" 2. Raising uncaught exceptions\n" +
150149
" Please catch all exceptions inside the nested operation\n" +
151-
" 3. Calling Continuation APIs\n",
152-
);
150+
" 3. Calling Continuation APIs\n";
151+
152+
const error = new RbValue(this.guest.rbErrinfo(), this, this.privateObject());
153+
if (error.call("nil?").toString() === "false") {
154+
message += "\n" + this.exceptionFormatter.format(error, this, this.privateObject());
155+
}
156+
throw new RbFatalError(message);
153157
},
154158
};
155159
// NOTE: The GC may collect objects that are still referenced by Wasm

0 commit comments

Comments
 (0)