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

Hotfix: promise rejection configuration #2239

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [8.1.2] - 2024-10-24

### Fixed

- Ensure `reportUnhandledPromiseRejectionsAsHandled` is correctly handled for all platforms [#2239](https://github.com/bugsnag/bugsnag-js/pull/2239)

## [8.1.1] - 2024-10-23

### Fixed
Expand Down
16 changes: 11 additions & 5 deletions packages/browser/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BugsnagBrowserStatic, { Breadcrumb, Session } from '../src/notifier'
import BugsnagBrowserStatic, { Breadcrumb, BrowserConfig, Session } from '../src/notifier'

const DONE = window.XMLHttpRequest.DONE

Expand Down Expand Up @@ -137,7 +137,8 @@ describe('browser notifier', () => {

it('accepts all config options', (done) => {
const Bugsnag = getBugsnag()
Bugsnag.start({

const completeConfig: Required<BrowserConfig> = {
apiKey: API_KEY,
appVersion: '1.2.3',
appType: 'worker',
Expand All @@ -161,18 +162,23 @@ describe('browser notifier', () => {
releaseStage: 'production',
maxBreadcrumbs: 20,
enabledBreadcrumbTypes: ['manual', 'log', 'request'],
context: 'contextual',
featureFlags: [],
plugins: [],
user: null,
metadata: {
debug: { foo: 'bar' }
},
logger: undefined,
logger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() },
redactedKeys: ['foo', /bar/],
collectUserIp: true,
maxEvents: 10,
generateAnonymousId: false,
trackInlineScripts: true
})
trackInlineScripts: true,
reportUnhandledPromiseRejectionsAsHandled: true
}

Bugsnag.start(completeConfig)
Bugsnag.notify(new Error('123'), (event) => {
return false
}, (err, event) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/electron/test/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe.skip('@bugsnag/electron types', () => {
plugins: [],
user: { id: '1234-abcd' },
appType: 'good',
codeBundleId: '1245'
codeBundleId: '1245',
reportUnhandledPromiseRejectionsAsHandled: true
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const stringWithLength = require('@bugsnag/core/lib/validators/string-with-lengt
const rnPackage = require('react-native/package.json')
const iserror = require('iserror')

const ALLOWED_IN_JS = ['onError', 'onBreadcrumb', 'logger', 'metadata', 'user', 'context', 'codeBundleId', 'plugins', 'featureFlags']
const ALLOWED_IN_JS = ['onError', 'onBreadcrumb', 'logger', 'metadata', 'user', 'context', 'codeBundleId', 'plugins', 'featureFlags', 'reportUnhandledPromiseRejectionsAsHandled']
const allowedErrorTypes = () => ({
unhandledExceptions: true,
unhandledRejections: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ describe('react native notifier', () => {
expect(NativeModules.BugsnagReactNative.addFeatureFlags).toHaveBeenCalled()
})

it('accepts the reportUnhandledPromiseRejectionsAsHandled config option', () => {
const warnMock = jest.spyOn(console, 'warn').mockImplementation(() => {})

Bugsnag.start({ reportUnhandledPromiseRejectionsAsHandled: true })

expect(warnMock).not.toHaveBeenCalled()
})

describe('isStarted()', () => {
it('returns false when the notifier has not been initialized', () => {
expect(Bugsnag.isStarted()).toBe(false)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/types/bugsnag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ReactNativeSchema extends Config {
}

// these properties are allowed to be configured in the JS layer
type Configurable = 'onError' | 'onBreadcrumb' | 'logger' | 'metadata' | 'user' | 'context' | 'plugins' | 'codeBundleId' | 'featureFlags'
type Configurable = 'onError' | 'onBreadcrumb' | 'logger' | 'metadata' | 'user' | 'context' | 'plugins' | 'codeBundleId' | 'featureFlags' | 'reportUnhandledPromiseRejectionsAsHandled'

type ReactNativeConfig = Pick<ReactNativeSchema, Configurable>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Bugsnag = require('@bugsnag/node')
Bugsnag.start({
reportUnhandledPromiseRejectionsAsHandled: true,
apiKey: process.env.BUGSNAG_API_KEY,
endpoints: {
notify: process.env.BUGSNAG_NOTIFY_ENDPOINT,
sessions: process.env.BUGSNAG_SESSIONS_ENDPOINT
}
})

Promise.reject(new Error('not handled'))
8 changes: 4 additions & 4 deletions test/node/features/unhandled_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ Scenario: reporting unhandled promise rejections
And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection.js"
And the "lineNumber" of stack frame 0 equals 10

Scenario: reporting unhandled promise rejections
And I run the service "unhandled" with the command "node scenarios/unhandled-promise-rejection"
Scenario: reporting unhandled promise rejections as handled
And I run the service "unhandled" with the command "node scenarios/unhandled-promise-rejection-as-handled"
And I wait to receive an error
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier
And the event "unhandled" is true
And the event "unhandled" is false
And the event "severity" equals "error"
And the event "severityReason.type" equals "unhandledPromiseRejection"
And the exception "errorClass" equals "Error"
And the exception "message" equals "not handled"
And the exception "type" equals "nodejs"
And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection.js"
And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection-as-handled.js"
And the "lineNumber" of stack frame 0 equals 10
Copy link
Member Author

@gingerbenw gingerbenw Oct 24, 2024

Choose a reason for hiding this comment

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

This was previously a duplicate of the scenario above, hence rewriting and not adding a new one


Scenario: not reporting unhandledRejections when autoDetectErrors is off
Expand Down
Loading