Skip to content

Commit

Permalink
fix: parse TypeError etc correctly
Browse files Browse the repository at this point in the history
In addition to Error, there's also TypeError, RangeError, SyntaxError etc.

Fixes #29
  • Loading branch information
bobbyg603 committed Aug 1, 2022
1 parent 074cbae commit 3ebee0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stack-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class StackConverter {

private static getChromiumErrorLineOrEmpty(stack: string): string {
const parts = stack.split('\n');
if (parts[0].startsWith('Error:')) {
if (parts[0].match('Error:')) {
return parts[0];
}

Expand Down
16 changes: 16 additions & 0 deletions spec/stack-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ describe('StackConverter', () => {
);
});

it('should include exception message in stack', async () => {
const baseFile = 'stack-2';
const mapFilePath = path.join(TESTING_DATA_DIR, `${baseFile}.js.map`);
const stackConverter = new StackConverter([mapFilePath]);
const stackFilePath = path.join(TESTING_DATA_DIR, `${baseFile}.txt`);
const stackText = readStack(stackFilePath);
const { error, stack } = await stackConverter.convert(stackText);
expect(error).toBeUndefined();
expect(normalize(stack)).toEqual(
normalize(
`TypeError: Bug.Splat is not a function
at TypeError (webpack:///projects/my-angular-crasher/src/app/app.component.ts:33:4)`
)
);
});

it('read in stack trace containing frames from multiple files missing source maps converts stack with errors', async () => {
const stackAndSourceMapDir = path.join(TESTING_DATA_DIR, 'dir-multiple-source-map-files');
const stackConverter = new StackConverter([
Expand Down
1 change: 1 addition & 0 deletions spec/test-data/stack-2.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions spec/test-data/stack-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TypeError: Bug.Splat is not a function
at new AppComponent (http://127.0.0.1:8080/stack-2.js:86:20)

1 comment on commit 3ebee0a

@daveplunkett
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - approved!

Please sign in to comment.