From e0bcc035697a5d363a55cd7c574a0f530274db82 Mon Sep 17 00:00:00 2001 From: Bobby Galli Date: Mon, 19 Apr 2021 15:01:39 -0400 Subject: [PATCH 1/2] Support the top line of the Error object Renames tests to stack-converter.tests.ts Fixes #11 --- ...ckconverter.test.ts => stack-converter.test.ts} | 11 +++++++---- lib/stack-converter.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) rename __tests__/{stackconverter.test.ts => stack-converter.test.ts} (91%) diff --git a/__tests__/stackconverter.test.ts b/__tests__/stack-converter.test.ts similarity index 91% rename from __tests__/stackconverter.test.ts rename to __tests__/stack-converter.test.ts index e6cf561..6575768 100644 --- a/__tests__/stackconverter.test.ts +++ b/__tests__/stack-converter.test.ts @@ -1,6 +1,6 @@ import * as fs from "fs"; import * as path from "path"; -import { StackConverter } from "../src/stackconverter"; +import { StackConverter } from "../lib/stack-converter"; const TESTING_DIR = "__tests__"; const TESTING_DATA_DIR = path.join(TESTING_DIR, "test-data"); @@ -84,7 +84,8 @@ describe("StackConverter", () => { const { error, stack } = await stackConverter.convert(stackText); expect(error).toBeUndefined(); expect(stack).toMatchInlineSnapshot(` - " at (dummy.ts:2:31) + "Error: Crush your bugs! + at (dummy.ts:2:31) at (dummy.ts:2:31) at (dummy.ts:2:31) at (dummy.ts:2:31) @@ -109,7 +110,8 @@ describe("StackConverter", () => { expect(error).toBeUndefined(); expect(stackText).toEqual(stackText); expect(stack).toMatchInlineSnapshot(` - " at (webpack:///src/app/common/services/bugsplat-custom-error-handler/bugsplat-custom-error-handler.ts:32:16) + "Error: Http failure response for https://app.bugsplat.com/api/subscription.php?database=AutoDb_04102021_95345: 502 OK + at (webpack:///src/app/common/services/bugsplat-custom-error-handler/bugsplat-custom-error-handler.ts:32:16) at Generator.next () at next (webpack:///node_modules/tslib/tslib.es6.js:74:70) at executor (webpack:///node_modules/zone.js/dist/zone-evergreen.js:960:32) @@ -131,7 +133,8 @@ describe("StackConverter", () => { expect(error).toBeUndefined(); expect(stackText).toEqual(stackText); expect(stack).toMatchInlineSnapshot(` - " at (webpack:///src/app/common/services/bugsplat-custom-error-handler/bugsplat-custom-error-handler.ts:32:16) + "Error: Http failure response for https://app.bugsplat.com/api/subscription.php?database=AutoDb_04102021_95345: 502 OK + at (webpack:///src/app/common/services/bugsplat-custom-error-handler/bugsplat-custom-error-handler.ts:32:16) at Generator.next () at next (webpack:///node_modules/tslib/tslib.es6.js:74:70) at executor (webpack:///node_modules/zone.js/dist/zone-evergreen.js:960:32) diff --git a/lib/stack-converter.ts b/lib/stack-converter.ts index d055340..ce8f170 100644 --- a/lib/stack-converter.ts +++ b/lib/stack-converter.ts @@ -63,6 +63,11 @@ export class StackConverter { const sourceMaps: { [filename: string]: SourceMapConsumer } = {}; const sourceMapErrors: { [filename: string]: boolean } = {}; + const errorLine = StackConverter.getChromiumErrorLineOrEmpty(stack); + if (errorLine) { + buff.push(errorLine); + } + for (const frame of stackFrames) { const { file, methodName, lineNumber, column } = frame; if (file in sourceMapErrors) { @@ -138,6 +143,15 @@ export class StackConverter { return `${StackConverter.INDENT}at ${method} (${file}:${line}:${column})` + (comment ? ' ***' + comment : ''); } + private static getChromiumErrorLineOrEmpty(stack: string): string { + const parts = stack.split('\n'); + if (parts[0].startsWith('Error:')) { + return parts[0]; + } + + return ''; + } + private static async sourceMapFromFile(file: string): Promise<{sourceMap?: SourceMapConsumer, error?: string}> { if (!file) { return { error: 'file name was empty' }; From b3d6e05df61c5441203ef8488030c42147334f91 Mon Sep 17 00:00:00 2001 From: Bobby Galli Date: Tue, 20 Apr 2021 09:44:53 -0400 Subject: [PATCH 2/2] Fixed tests on Windows. --- __tests__/stack-converter.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/__tests__/stack-converter.test.ts b/__tests__/stack-converter.test.ts index 6575768..aaaadb4 100644 --- a/__tests__/stack-converter.test.ts +++ b/__tests__/stack-converter.test.ts @@ -50,20 +50,22 @@ describe("StackConverter", () => { test("source map file that does not exist results stack frame with error message", async () => { const missingJsFileName = "does-not-exist.js"; - const missingJsMapPath = path.join(TESTING_DATA_DIR, `${missingJsFileName}.map`); + const missingJsMapFileName = `${missingJsFileName}.map` + const missingJsMapPath = path.join(TESTING_DATA_DIR, missingJsMapFileName); const stackConverter = new StackConverter([missingJsMapPath]); const { error, stack } = await stackConverter.convert(` at hello (${missingJsFileName}:1:1337)`); expect(error).toBeFalsy(); - expect(stack).toMatch(new RegExp(`Error loading source map for frame \\(file ${missingJsMapPath} does not exist or is inaccessible\\)`)); + expect(stack).toMatch(new RegExp(`Error loading source map for frame \\(file .*${missingJsMapFileName} does not exist or is inaccessible\\)`)); }); test("empty source map file results stack frame with error message", async () => { const emptyJsFileName = "empty.js"; - const emptyJsMapPath = path.join(TESTING_DATA_DIR, `${emptyJsFileName}.map`); + const emptyJsMapFileName = `${emptyJsFileName}.map` + const emptyJsMapPath = path.join(TESTING_DATA_DIR, emptyJsMapFileName); const stackConverter = new StackConverter([emptyJsMapPath]); const { error, stack } = await stackConverter.convert(` at hello (${emptyJsFileName}:1:1337)`); expect(error).toBeFalsy(); - expect(stack).toMatch(new RegExp(`Error loading source map for frame \\(file ${emptyJsMapPath} was empty\\)`)); + expect(stack).toMatch(new RegExp(`Error loading source map for frame \\(file .*${emptyJsMapFileName} was empty\\)`)); }); test("source map file that can't be parsed results stack frame with error message", async () => {