Skip to content

Commit

Permalink
fix(electron): do not log errors when sync layer is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Nov 15, 2023
1 parent 8fcdee2 commit 7a51cff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 1 addition & 4 deletions packages/plugin-electron-client-state-persistence/src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static bool throw_error_from_status(napi_env env, BECSP_STATUS status) {
const char *code = "BugsnagSyncError";
switch (status) {
case BECSP_STATUS_SUCCESS:
case BECSP_STATUS_NOT_INSTALLED:
return false;
case BECSP_STATUS_INVALID_JSON:
napi_throw_error(env, code, "Failed to convert argument to JSON");
Expand All @@ -95,10 +96,6 @@ static bool throw_error_from_status(napi_env env, BECSP_STATUS status) {
case BECSP_STATUS_NULL_PARAM:
napi_throw_type_error(env, code, "Expected argument to be non-null");
break;
case BECSP_STATUS_NOT_INSTALLED:
napi_throw_error(env, code,
"Sync layer is not installed, first call install()");
break;
case BECSP_STATUS_UNKNOWN_FAILURE:
napi_throw_error(env, code, "Failed to synchronize data");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,24 @@ describe('handling poor inputs', () => {
expect(update).toThrow('Wrong number of arguments, expected 1')
})
})

describe('handling sync layer not being installed', () => {
it('does not throw when sync layer is not installed', () => {
const updateUser = () => NativeClient.updateUser('1234', '[email protected]', 'User')
expect(updateUser).not.toThrow()

const updateContext = () => NativeClient.updateContext('1234')
expect(updateContext).not.toThrow()

const updateMetadata = () => NativeClient.updateMetadata('widget', { id: '14', count: 340 })
expect(updateMetadata).not.toThrow()

const leaveBreadcrumb = () => NativeClient.leaveBreadcrumb('Button clicked')
expect(leaveBreadcrumb).not.toThrow()

const updateFeatureFlags = () => NativeClient.updateFeatureFlags(
[{ featureFlag: 'name 1' }, { featureFlag: 'name 2' }]
)
expect(updateFeatureFlags).not.toThrow()
})
})
2 changes: 1 addition & 1 deletion scripts/cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SUPPRESSED_ERRORS=(\
--suppress='knownConditionTrueFalse:*/deps/parson/parson.c:600' \
--suppress='memleak:*/plugin-electron-client-state-persistence/src/deps/tinycthread/tinycthread.c:620' \
--suppress='constParameter:*/plugin-electron-client-state-persistence/src/deps/tinycthread/tinycthread.c:591' \
--suppress='unusedFunction:*/plugin-electron-client-state-persistence/src/api.c:513' \
--suppress='unusedFunction:*/plugin-electron-client-state-persistence/src/api.c:510' \
--suppress='unusedFunction:*/plugin-electron-app/src/api.c:60')

# Shared arguments:
Expand Down

0 comments on commit 7a51cff

Please sign in to comment.