Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub action update - added "synchronize" #1988

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/typescript_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: TypeScript Check

on:
pull_request:
types: [opened, reopened, edited]
types: [opened, reopened, edited, synchronize]

jobs:
# Test job
Expand Down
16 changes: 13 additions & 3 deletions src/lib/engine/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
}

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
Expand All @@ -91,7 +92,7 @@

const stack = (gameError.error.stack ? normalizeStack(gameError.error.stack) : null) ?? []

let [line, col] = findErrorLineCol(gameError.error.stack)

Check failure on line 95 in src/lib/engine/error.ts

View workflow job for this annotation

GitHub Actions / build

Expected 2 arguments, but got 1.

stack.reverse()

Expand All @@ -113,13 +114,22 @@

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 {
descriptionLines.unshift(` at ${item.callSite}`)
}
}

// 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'),
Expand All @@ -136,7 +146,7 @@
* 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
Expand All @@ -147,7 +157,7 @@

if (location) {
let lineCol = location[1]!.split(":").map(Number)
line = lineCol[0]! - 2 - 1
line = lineCol[0]! - lineOffset
col = lineCol[1]!
}

Expand Down
11 changes: 9 additions & 2 deletions src/lib/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading