Skip to content

Commit

Permalink
Merge pull request #563 from bugsnag/empty-stacktrace-inline-script-bug
Browse files Browse the repository at this point in the history
Prevent error when running inline script plugin on empty stacktraces
  • Loading branch information
bengourley authored Jun 25, 2019
2 parents cd7c3d8 + 0187196 commit c506250
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Fixed

- (plugin-inline-script): Ensure inline script content callback doesn't cause error logs when there are no stackframes [#559](https://github.com/bugsnag/bugsnag-js/pull/559) / [#563](https://github.com/bugsnag/bugsnag-js/pull/563)

## 6.3.1 (2019-06-17)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
}

// only attempt to grab some surrounding code if we have a line number
if (frame.lineNumber === undefined) return
if (!frame || !frame.lineNumber) return
frame.code = addSurroundingCode(frame.lineNumber)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { describe, it, expect } = global
const { describe, it, expect, spyOn } = global

const plugin = require('../')

Expand Down Expand Up @@ -157,4 +157,37 @@ Lorem ipsum dolor sit amet.
})
expect(payloads[0].events[0].metaData.script).toBeDefined()
})

it('works when the stacktrace is empty', () => {
const scriptContent = `console.log("EMPTY")`
const document = {
scripts: [ { innerHTML: scriptContent } ],
currentScript: { innerHTML: scriptContent },
documentElement: {
outerHTML: `<p>
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
</p>
<script>${scriptContent}
</script>
<p>more content</p>`
}
}
const window = { location: { href: 'https://app.bugsnag.com/errors' } }

const client = new Client(VALID_NOTIFIER)
const payloads = []
client.setOptions({ apiKey: 'API_KEY_YEAH' })
client.configure()
client.use(plugin, document, window)

expect(client.config.beforeSend.length).toBe(1)
client.delivery(client => ({ sendReport: (payload) => payloads.push(payload) }))
const spy = spyOn(client._logger, 'error')
client.notify(new Report('EmptyStacktrace', 'Has nothing in it', []))
expect(payloads.length).toEqual(1)
expect(payloads[0].events[0].stacktrace).toEqual([])
expect(spy).toHaveBeenCalledTimes(0)
})
})

0 comments on commit c506250

Please sign in to comment.