diff --git a/packages/npm-packages/ruby-wasm-wasi/src/vm.ts b/packages/npm-packages/ruby-wasm-wasi/src/vm.ts index 6631164acd..a72b8cfd77 100644 --- a/packages/npm-packages/ruby-wasm-wasi/src/vm.ts +++ b/packages/npm-packages/ruby-wasm-wasi/src/vm.ts @@ -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" + @@ -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