atom / exception-reporting

Catches exceptions and forwards them to bugsnag
MIT License
10 stars 19 forks source link

Fails to report error when stacktrace includes core JavaScript API #40

Closed jasonrudolph closed 6 years ago

jasonrudolph commented 6 years ago

Description

When an exception occurs, and the stacktrace includes a core JavaScript API, the exception-reporting package fails to report the exception to bugsnag. For example, the stacktrace below involves an exception in the fuzzy-finder package, and the stacktrace includes a call to Array.forEach:

     ~/github/fuzzy-finder/lib/main.js:81 Uncaught Error
         at forEach (/Users/j/github/fuzzy-finder/lib/main.js:81:31)
===>     at Array.forEach (native)     <===
         at Object.createProjectView (/Users/j/github/fuzzy-finder/lib/main.js:81:9)
         at HTMLElement.fuzzy-finder:toggle-file-finder (/Users/j/github/fuzzy-finder/lib/main.js:12:14)
         at CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app/src/command-registry.js:384:49)
         at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent      (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
         at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent      (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
         at WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app/src/window-event-handler.js:110:40)

When the exception-reporting package attempts to normalize the paths in the stacktrace, the package errors when it encounters Array.forEach in the stacktrace. Instead of reporting the exception to bugsnag, the package logs an error to the console:

Error reporting uncaught exception TypeError: Cannot read property 'replace' of null
    at Reporter.normalizePath (~/github/exception-reporting/lib/reporter.js:71:27)
    at Reporter.scrubPath (~/github/exception-reporting/lib/reporter.js:77:31)
    at ~/github/exception-reporting/lib/reporter.js:61:20
    at Array.map (native)
    at Reporter.buildStackTraceJSON (~/github/exception-reporting/lib/reporter.js:59:40)
    at Reporter.buildExceptionJSON (~/github/exception-reporting/lib/reporter.js:54:24)
    at Reporter.buildNotificationJSON (~/github/exception-reporting/lib/reporter.js:33:27)
    at Reporter.reportUncaughtException (~/github/exception-reporting/lib/reporter.js:229:30)
    at ~/github/atom/out/app/node_modules/exception-reporting/lib/main.js:25:23
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at window.onerror (/Applications/Atom.app/Contents/Resources/app/src/atom-environment.js:949:26)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app/src/window-event-handler.js:110:40)

Steps to Reproduce

  1. Clone the repository for another bundled package and apm link it. We'll use fuzzy-finder for this example:
    1. git clone atom/fuzzy-finder
    2. cd fuzzy-finder
    3. git checkout v1.8.1
    4. apm install && apm link
  2. In the fuzzy-finder code, edit main.js to trigger an error that has a core JavaScript API in the stacktrace:

    --- a/lib/main.js
    +++ b/lib/main.js
    @@ -78,6 +78,8 @@ module.exports = {
       },
    
       createProjectView () {
    +    [0].forEach(() => { throw new Error('whoops') })
    +
         this.stopLoadPathsTask()
    
         if (this.projectView == null) {
  3. Clone the atom/exception-reporting repository and apm link the package:
    1. git clone atom/exception-reporting
    2. cd exception-reporting
    3. git checkout v0.43.1
    4. apm install && apm link
  4. In the exception-reporting code, edit lib/reporter.js so that it will treat our local copy of fuzzy-finder as a bundled package for error reporting purposes:

    --- a/lib/reporter.js
    +++ b/lib/reporter.js
    @@ -253,7 +253,7 @@ export default class Reporter {
       }
    
       isBundledFile (fileName) {
    -    return this.normalizePath(fileName).indexOf(this.resourcePath) === 0
    +    return true
       }
    
       isTeletypeFile (fileName) {
  5. Open Atom
  6. Trigger the Fuzzy Finder: Toggle File Finder command to force the error above to be thrown

Expected behavior: Error should be successfully posted to bugsnag

Actual behavior: Error is not reported to bugsnag

Reproduces how often: 100%

Versions

exception-reporting 0.43.1

$ atom --version
Atom    : 1.27.0-dev-6dd878d
Electron: 1.7.11
Chrome  : 58.0.3029.110
Node    : 7.9.0

/cc @as-cii (since we encountered this issue while pairing today)

daviwil commented 6 years ago

This issue was moved to atom/atom#18141