Skip to content

Commit

Permalink
Merge pull request #2241 from bugsnag/release/v8.1.2
Browse files Browse the repository at this point in the history
Release v8.1.2
  • Loading branch information
gingerbenw authored Oct 25, 2024
2 parents 356951b + 6abd366 commit 3f83f88
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 14 deletions.
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-25

### 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
2 changes: 1 addition & 1 deletion scripts/generate-react-native-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (!process.env.SKIP_GENERATE_FIXTURE) {
}

// create the test fixture
const RNInitArgs = ['@react-native-community/cli@latest', 'init', 'reactnative', '--directory', fixtureDir, '--version', reactNativeVersion, '--npm', '--skip-install']
const RNInitArgs = ['@react-native-community/cli@latest', 'init', 'reactnative', '--directory', fixtureDir, '--version', reactNativeVersion, '--pm', 'npm', '--skip-install']
execFileSync('npx', RNInitArgs, { stdio: 'inherit' })

replaceGeneratedFixtureFiles()
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'))
10 changes: 5 additions & 5 deletions test/node/features/unhandled_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ 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 "lineNumber" of stack frame 0 equals 10
And the "file" of stack frame 0 equals "scenarios/unhandled-promise-rejection-as-handled.js"
And the "lineNumber" of stack frame 0 equals 11

Scenario: not reporting unhandledRejections when autoDetectErrors is off
And I run the service "unhandled" with the command "node scenarios/unhandled-promise-rejection-auto-notify-off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { UnhandledNativeErrorScenario } from './scenarios/UnhandledNativeErrorSc
export { UnhandledJsErrorScenario } from './scenarios/UnhandledJsErrorScenario'
export { UnhandledJsErrorSeverityScenario } from './scenarios/UnhandledJsErrorSeverityScenario'
export { UnhandledJsPromiseRejectionScenario } from './scenarios/UnhandledJsPromiseRejectionScenario'
export { UnhandledJsPromiseRejectionAsHandledScenario } from './scenarios/UnhandledJsPromiseRejectionAsHandledScenario'
export { RCTFatalScenario } from './scenarios/RCTFatalScenario'

// api-key-ios.feature
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Scenario from './Scenario'

export class UnhandledJsPromiseRejectionAsHandledScenario extends Scenario {
constructor (configuration, jsConfig) {
super()
jsConfig.reportUnhandledPromiseRejectionsAsHandled = true
}

run () {
Promise.reject(new Error('UnhandledJsPromiseRejectionAsHandledScenario'))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Scenario from './Scenario'

export class UnhandledJsPromiseRejectionAsHandledScenario extends Scenario {
constructor (configuration, jsConfig) {
super()
jsConfig.reportUnhandledPromiseRejectionsAsHandled = true
}

run () {
Promise.reject(new Error('UnhandledJsPromiseRejectionAsHandledScenario'))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { UnhandledNativeErrorScenario } from './UnhandledNativeErrorScenario'
export { UnhandledJsErrorScenario } from './UnhandledJsErrorScenario'
export { UnhandledJsErrorSeverityScenario } from './UnhandledJsErrorSeverityScenario'
export { UnhandledJsPromiseRejectionScenario } from './UnhandledJsPromiseRejectionScenario'
export { UnhandledJsPromiseRejectionAsHandledScenario } from './UnhandledJsPromiseRejectionAsHandledScenario'
export { RCTFatalScenario } from './RCTFatalScenario'

// api-key-ios.feature
Expand Down
8 changes: 8 additions & 0 deletions test/react-native/features/unhandled-android.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Scenario: Reporting an Unhandled promise rejection
And the event "unhandled" is true
And the exception "message" equals "UnhandledJsPromiseRejectionScenario"

Scenario: Reporting an Unhandled promise rejection as handled
When I run "UnhandledJsPromiseRejectionAsHandledScenario"
Then I wait to receive an error
And the exception "errorClass" equals "Error"
And the exception "type" equals "reactnativejs"
And the event "unhandled" is false
And the exception "message" equals "UnhandledJsPromiseRejectionAsHandledScenario"

Scenario: Reporting an Unhandled Native error
When I run "UnhandledNativeErrorScenario" and relaunch the crashed app
And I configure Bugsnag for "UnhandledNativeErrorScenario"
Expand Down
8 changes: 8 additions & 0 deletions test/react-native/features/unhandled-ios.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Scenario: Reporting an Unhandled promise rejection
And the event "unhandled" is true
And the exception "message" equals "UnhandledJsPromiseRejectionScenario"

Scenario: Reporting an Unhandled promise rejection as handled
When I run "UnhandledJsPromiseRejectionAsHandledScenario"
Then I wait to receive an error
And the exception "errorClass" equals "Error"
And the exception "type" equals "reactnativejs"
And the event "unhandled" is false
And the exception "message" equals "UnhandledJsPromiseRejectionAsHandledScenario"

Scenario: Reporting an Unhandled Native error
When I run "UnhandledNativeErrorScenario" and relaunch the crashed app
And I configure Bugsnag for "UnhandledNativeErrorScenario"
Expand Down

0 comments on commit 3f83f88

Please sign in to comment.