Skip to content

Commit

Permalink
fix(breadcrumbs): Always convert breadcrumb data to a valid object
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Apr 21, 2023
1 parent ad6c299 commit b5cf7c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/js/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { normalize } from '@sentry/utils';

/**
* Converts any input into a valid record with string keys.
*/
export function convertToRecord(wat: unknown): Record<string, unknown> {
const normalized: unknown = normalize(wat);
if (typeof normalized !== 'object') {
return {
unknown: normalized,
};
} else {
return normalized as Record<string, unknown>;
}
}
3 changes: 2 additions & 1 deletion src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { ReactNativeClientOptions } from './options';
import type { RequiredKeysUser } from './user';
import { isTurboModuleEnabled } from './utils/environment';
import { utf8ToBytes } from './vendor';
import { convertToRecord } from './utils/normalize';

const RNSentry: Spec | undefined = isTurboModuleEnabled()
? TurboModuleRegistry.get<Spec>('RNSentry')
Expand Down Expand Up @@ -381,7 +382,7 @@ export const NATIVE: SentryNativeWrapper = {
...breadcrumb,
// Process and convert deprecated levels
level: breadcrumb.level ? this._processLevel(breadcrumb.level) : undefined,
data: breadcrumb.data ? normalize(breadcrumb.data) : undefined,
data: breadcrumb.data ? convertToRecord(breadcrumb.data) : undefined,
});
},

Expand Down

0 comments on commit b5cf7c0

Please sign in to comment.