From 96fb6c68e24aecd8f6465a53a8a3d37aa446b21c Mon Sep 17 00:00:00 2001 From: Joseph Dylan Stewart Date: Wed, 3 Aug 2022 16:34:27 -0700 Subject: [PATCH] Fix incorrect stack frame assumption --- src/UserCodeRunner.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/UserCodeRunner.ts b/src/UserCodeRunner.ts index 07d76e9..96efb2b 100644 --- a/src/UserCodeRunner.ts +++ b/src/UserCodeRunner.ts @@ -390,9 +390,13 @@ export class UserCodeRuntimeError extends UserCodeError { public get location(): { line: number; column: number } { const stack = parse(this.error); + const userFileStackFrame = stack.find(callSite => callSite.getFileName() === USER_CODE_FILENAME); + if (userFileStackFrame === undefined) { + throw new Error('Runtime error detected outside of user code execution path. This is most likely a bug in the additional library source.'); + } const originalPosition = this.sourceMap.originalPositionFor({ - line: stack[0].getLineNumber()!, - column: stack[0].getColumnNumber()!, + line: userFileStackFrame.getLineNumber()!, + column: userFileStackFrame.getColumnNumber()!, }); return { line: originalPosition.line!,