stacktracejs / error-stack-parser

Extract meaning from JS Errors
https://www.stacktracejs.com/#!/docs/error-stack-parser
MIT License
450 stars 52 forks source link

Parse Node stacktraces correctly for filenames with spaces #47

Closed bengourley closed 5 years ago

bengourley commented 5 years ago

Description

If a filename has spaces in it, it throws off the tokenization of the stackframe, resulting in an incorrect StackFrame object. The filename is reported as everything after the space, e.g.

Parsing this error…

Error
    at Object.<anonymous> (/Users/bengourley/Development/error-stack-parser/scratch/my project/index.js:2:9)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

Results in this at stackframe[0]:

{
  columnNumber: 9,
  lineNumber: 2,
  fileName: 'project/index.js',
  functionName: 'Object.<anonymous> (/Users/bengourley/Development/error-stack-parser/scratch/my',
  source: '    at Object.<anonymous> (/Users/bengourley/Development/error-stack-parser/scratch/my project/index.js:2:9)'
}

The fix is a little clunky I'll admit – the neatest thing would be to find a regex to supply instead of the split(/\s+/) call, which would only split on spaces that did not occur with parentheses, but I couldn't come up with one.

Motivation and Context

Reported on this repo #46 and now Bugsnag's users are seeing it bugsnag/bugsnag-js#586.

How Has This Been Tested?

Added a test case which fails before the fix is applied.

Types of changes

Checklist: