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

[PLAT-7801] Add early check for undefined apiKey #1738

Merged
merged 3 commits into from
May 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Small performance improvements to `Bugnag.start`
[bugsnag-android#1680](https://github.com/bugsnag/bugsnag-android/pull/1680)
- (plugin-react|plugin-vue|plugin-react-navigation|plugin-react-native-navigation) Set `@bugsnag/core` to be an optional peer dependency to avoid unmet peer dependency warnings [#1735](https://github.com/bugsnag/bugsnag-js/pull/1735)
- (electron) Improved error message when no apiKey is provided to Bugsnag.start() [#1738](https://github.com/bugsnag/bugsnag-js/pull/1738)

## v7.16.4 (2022-05-03)

Expand Down
6 changes: 6 additions & 0 deletions packages/electron/src/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const { schema } = require('../config/main')
Event.__type = 'electronnodejs'

module.exports = (opts) => {
// check api key has been provided as we need it to create the FileStore
// which happens before the API key is validated
if (typeof opts.apiKey !== 'string') {
throw new Error('No Bugsnag API Key set')
}

const filestore = new FileStore(
opts.apiKey,
electron.app.getPath('userCache'),
Expand Down
13 changes: 13 additions & 0 deletions packages/electron/src/client/test/client.test-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import createClient from '../main'

describe('@bugsnag/electron client', () => {
describe('createClient', () => {
it('throws an error when an apiKey is not provided', () => {
expect(
() => {
createClient({})
}
).toThrowError('No Bugsnag API Key set')
})
})
})