Skip to content

Commit cbde0a1

Browse files
Catch exceptions thrown during rbVmBugreport
The `rbVmBugreport` operation itself can throw exceptions because the VM state might be in a bad shape at this point due to unexpected non-RbError exceptions. And if it does, it forgets to report the original exception that actually caused the bad state. This change catches exceptions thrown during `rbVmBugreport` and just logs them instead of rethrowing them to ensure that the original exception is not lost.
1 parent 650eb3e commit cbde0a1

File tree

1 file changed

+5
-1
lines changed
  • packages/npm-packages/ruby-wasm-wasi/src

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,11 @@ function wrapRbOperation<R>(vm: RubyVM, body: () => R): R {
735735
}
736736
// All JS exceptions triggered by Ruby code are translated to Ruby exceptions,
737737
// so non-RbError exceptions are unexpected.
738-
vm.guest.rbVmBugreport();
738+
try {
739+
vm.guest.rbVmBugreport();
740+
} catch (e) {
741+
console.error("Tried to report internal Ruby VM state but failed: ", e);
742+
}
739743
if (e instanceof WebAssembly.RuntimeError && e.message === "unreachable") {
740744
const error = new RbError(`Something went wrong in Ruby VM: ${e}`);
741745
error.stack = e.stack;

0 commit comments

Comments
 (0)