Skip to content

Commit 00a8824

Browse files
Handle SystemStackError: stack level too deep properly
`SystemStackError` sometimes returns nil for `#backtrace`, so we should it before formatting call frames.
1 parent c5403c1 commit 00a8824

File tree

1 file changed

+12
-2
lines changed
  • packages/npm-packages/ruby-wasm-wasi/src

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ class RbExceptionFormatter {
406406
})();
407407

408408
const backtrace = error.call("backtrace");
409+
if (backtrace.call("nil?").toString() === "true") {
410+
return this.formatString(
411+
error.call("class").toString(),
412+
error.toString()
413+
);
414+
}
409415
const firstLine = backtrace.call("at", zeroLiteral);
410416
const restLines = backtrace
411417
.call("drop", oneLiteral)
@@ -419,9 +425,13 @@ class RbExceptionFormatter {
419425
formatString(
420426
klass: string,
421427
message: string,
422-
backtrace: [string, string]
428+
backtrace?: [string, string]
423429
): string {
424-
return `${backtrace[0]}: ${message} (${klass})\n${backtrace[1]}`;
430+
if (backtrace) {
431+
return `${backtrace[0]}: ${message} (${klass})\n${backtrace[1]}`;
432+
} else {
433+
return `${klass}: ${message}`;
434+
}
425435
}
426436
}
427437

0 commit comments

Comments
 (0)