Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a correct error message when null is passed to notify() #400

Closed
wants to merge 411 commits into from

Conversation

bobjflong
Copy link

@bobjflong bobjflong commented Oct 26, 2018

Goal

Currently, calling notify(null) incorrectly generates this error: Bugsnag usage error. notify() expected error/opts parameters, got unsupported object.

The intent from the code appears to be that this would instead generate: Bugsnag usage error. notify() expected error/opts parameters, got nothing

The issue is caused by normaliseError calling typeof error, which is object for null. So this code path was being hit: https://github.com/bugsnag/bugsnag-js/compare/master...bobjflong:BL/null?expand=1#diff-d038e8e69f5ea867f38281dc1f40df19R240

There is existing null check code, but it wasn't being hit as a result.

Changeset

Added

Removed

Changed

I've added a null check to the last branch in normaliseError.

Tests

I've added a specific unit test for this case.

Discussion

Alternative Approaches

Outstanding Questions

Linked issues

Review

For the submitter, initial self-review:

  • [?] Commented on code changes inline explain the reasoning behind the approach - necessary?
  • Reviewed the test cases added for completeness and possible points for discussion
  • [?] A changelog entry was added for the goal of this pull request - necessary?
  • Check the scope of the changeset - is everything in the diff required for the pull request?
  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

bengourley and others added 25 commits May 23, 2018 17:48
Enables session tracking by default, and makes some requisite changes to ensure the relevant endpoints are properly configured. The options `endpoint` and `sessionEndpoint` are soft-deprecated, and they are replaced by the `endpoints: { notify, sessions }` object.
* test: Add a failing test for known stacktrace parsing bug

URL paths with "@" in them incorrectly parse in Firefox/Safari due to a bug in the
error-stack-parser module

* fix: Upgrade to latest stacktracejs modules

error-stack-parser contains a bugfix for the test in the previous commit
stack-generator published
a long-term dangling PR which we were depending on in a fork, so this just switches back to the main
package

* chore: Rebuild

* test: Remove unnecessary assertion which is different for different browsers

* test: Generalise assertion to cater for variation across browsers
* test: Add filename assertions for unhandled syntax errors

This commit adds a failing test for the stacktrace of syntax errors in chrome. The stacktrace
doesn't have any frames, yet it gets passed over to error-stack-parser which incorrectly adds the
error message as the file name.

* fix: Don't attempt to parse a stacktrace if it doesn't contain any frames

SyntaxErrors in Chrome have an error.stack property which is just `${err.name}: ${err.message}` and
no stack frames but because the err.stack value is truthy we attempted to parse it with
error-stack-parser. The result of this was that the filename proeprty of the stackframes was not
correct and caused issues with grouping. This change causes Report.getStacktrace(err) to generate a
backtrace instead and then the file/line/col properties get filled in with the values from
window.onerror.

* chore: Rebuild
In iOS9 Safari, a request that violates the Content Security Policy (CSP) rules causes a `DOMException` to be thrown. Since v4.7.0, bugsnag calls `startSession()` synchronously upon startup, which means that any thrown error in that tick of the event loop results in the libary (and anything else in that synchronous execution context) to be unusable. The behaviour of iOS Safari was fixed in version 10, but since we support 9, this needs a workaround.

The xml-http-request transport mechanism already wrapped request.send() with a try/catch, but the error in this instance was coming from the request.open() call. The try/catch block was moved out out to include all of the synchronous code inside sendReport()/sendSession().
The badge key was out of date and referred to a CI run from a long time ago. The tests are now run
in a different way such that the status isn't reported to BrowserStack anyway, so it's best just to
remove this.
This is dropped by the UI and never shown as we can't render arrays in the breadcrumbs from what I can see.
BrowserStack appear to have removed emulators from their js testing product now, so the oldest
version of iOS we can test on is 10.3.
It looks like BrowserStack removed iOS enirely from their js testing product, according to this
page:
https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing
Dont send stacktrace as breadcrumb metadata
…-types

fix: Add missing properties to breadcrumb.d.ts
@bengourley
Copy link
Contributor

Hi. This PR was closed automatically when I switched out a new branch to master which didn't share any history with the version of master this pointed at. I'm going to take a fresh look at this issue with the new code. Thanks!

bengourley added a commit that referenced this pull request Apr 4, 2019
The existing logic prevented "null" from being reported correctly. This cleans up the logic and
makes sure it's all contained in the normaliseError() function.

Fixes #400.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants