diff --git a/.github/workflows/typescript_check.yml b/.github/workflows/typescript_check.yml index a6f73cbdf3..00152aa2ec 100644 --- a/.github/workflows/typescript_check.yml +++ b/.github/workflows/typescript_check.yml @@ -2,7 +2,7 @@ name: TypeScript Check on: pull_request: - types: [opened, reopened, edited] + types: [opened, reopened, edited, synchronize] jobs: # Test job diff --git a/src/lib/engine/error.ts b/src/lib/engine/error.ts index 065e642051..3c56af212d 100644 --- a/src/lib/engine/error.ts +++ b/src/lib/engine/error.ts @@ -75,7 +75,8 @@ const normalizeStack = (stack: string): StackItem[] | null => { } export const normalizeGameError = (gameError: GameError): NormalizedError => { - const lineOffset = 3 + const lineOffset = 2 + let addedLineCol = false if (gameError.kind === 'parse') { const { description, lineNumber, column } = gameError.error @@ -113,6 +114,7 @@ export const normalizeGameError = (gameError: GameError): NormalizedError => { if (fileName && item.lineNumber && item.column) { descriptionLines.unshift(` at ${item.callSite} (${fileName}:${item.lineNumber}:${item.column})`) + addedLineCol = true } else if (fileName) { descriptionLines.unshift(` at ${item.callSite} (${fileName})`) } else { @@ -120,6 +122,14 @@ export const normalizeGameError = (gameError: GameError): NormalizedError => { } } + // adds line number to infinite recursion + if (!addedLineCol && line && col && stack[0]) { + descriptionLines.unshift(` at ${stack[0]!.callSite} (index.ts:${line}:${col})`) + } else if (!addedLineCol && line && col) { + // might not always be eval in some edge cases - change if this is the case + descriptionLines.unshift(` at eval (index.ts:${line}:${col})`) + } + descriptionLines.unshift(`${gameError.error.name}: ${gameError.error.message}`) return { description: descriptionLines.join('\n'), @@ -136,7 +146,7 @@ export const normalizeGameError = (gameError: GameError): NormalizedError => { * Finds the line and column of innermost error from a stack. * This is modified code from V1. */ -function findErrorLineCol(stack: string | undefined): [number | null, number | null] { +function findErrorLineCol(stack: string | undefined, lineOffset: number): [number | null, number | null] { if (!stack) return [null, null] let line = null @@ -147,7 +157,7 @@ function findErrorLineCol(stack: string | undefined): [number | null, number | n if (location) { let lineCol = location[1]!.split(":").map(Number) - line = lineCol[0]! - 2 - 1 + line = lineCol[0]! - lineOffset col = lineCol[1]! } diff --git a/src/lib/engine/index.ts b/src/lib/engine/index.ts index 937e82c285..c162ca60a2 100644 --- a/src/lib/engine/index.ts +++ b/src/lib/engine/index.ts @@ -75,13 +75,20 @@ export function runGame(code: string, canvas: HTMLCanvasElement, onPageError: (e fn(...Object.values(api)) return { error: null, cleanup } } catch (error: any) { - // if there's an error code, it's most likely a babel error of some kind + // if there's an error code, it's most likely a babel error of some kind // other errors do not have an error code attached if (!error.code) { const normalizedError = normalizeGameError({ kind: "runtime", error }); - normalizedError!.line! += 1; return { error: normalizedError, cleanup }; } + + // At least for SyntaxErrors, the type of error shows as "unknown" instead of "SyntaxError" - this replaces that + if (error.message) { + if (error.message.split(":")[0] == 'unknown') { + error.message = error.message.replace('unknown', error.name) + } + } + return { error: { raw: error,