Skip to content

Commit fea0adf

Browse files
author
farfromrefug
committed
fix: prevent error while adding breadcrumbs
1 parent eb95ce0 commit fea0adf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/sentry/wrapper.android.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ export namespace NATIVE {
857857
}
858858

859859
if (otherUserKeys) {
860-
userInstance.setData(dataSerialize(otherUserKeys));
860+
userInstance.setData(dataSerialize(otherUserKeys, true));
861861
}
862862

863863
scope.setUser(userInstance);
@@ -897,7 +897,7 @@ export namespace NATIVE {
897897
breadcrumbInstance.setMessage(breadcrumb.message);
898898

899899
if (breadcrumb.data) {
900-
Object.keys(breadcrumb.data).forEach((key) => breadcrumbInstance.setData(key, dataSerialize(breadcrumb.data[key])));
900+
Object.keys(breadcrumb.data).forEach((key) => breadcrumbInstance.setData(key, dataSerialize(breadcrumb.data[key], true)));
901901
}
902902

903903
scope.addBreadcrumb(breadcrumbInstance);
@@ -945,7 +945,7 @@ export namespace NATIVE {
945945
if (!context || !key) {
946946
return;
947947
} else {
948-
scope.setContexts(key, dataSerialize(context));
948+
scope.setContexts(key, dataSerialize(context, true));
949949
}
950950
});
951951
}

src/sentry/wrapper.ios.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ function dataSerialize(data?: any, wrapPrimitives?: boolean) {
4646
}
4747

4848
if (Array.isArray(data)) {
49-
return NSArray.arrayWithArray((data as any).map(dataSerialize));
49+
return NSArray.arrayWithArray(data.map((el) => dataSerialize(el, wrapPrimitives)).filter((el) => el !== null));
5050
}
5151

52-
const node = {} as any;
53-
Object.keys(data).forEach(function (key) {
54-
const value = data[key];
55-
node[key] = dataSerialize(value, wrapPrimitives);
56-
});
52+
const node = Object.fromEntries(
53+
Object.entries(data)
54+
.map(([key, value]) => [key, dataSerialize(value, wrapPrimitives)])
55+
.filter(([, value]) => value !== null)
56+
);
5757
return NSDictionary.dictionaryWithDictionary(node);
5858
}
5959

@@ -344,7 +344,7 @@ export namespace NATIVE {
344344
delete toPassOptions[k];
345345
}
346346
});
347-
const mutDict = NSMutableDictionary.alloc().initWithDictionary(dataSerialize(toPassOptions) as any);
347+
const mutDict = NSMutableDictionary.alloc().initWithDictionary(dataSerialize(toPassOptions, true));
348348

349349
nSentryOptions = SentryOptions.alloc().initWithDictDidFailWithError(mutDict as any);
350350

@@ -386,7 +386,7 @@ export namespace NATIVE {
386386
if (beforeBreadcrumb) {
387387
const deserialized = dictToJSON(breadcrumb.serialize());
388388
const processed = beforeBreadcrumb(deserialized, null);
389-
const serialized = dataSerialize(processed) as NSDictionary<string, any>;
389+
const serialized = dataSerialize(processed, true) as NSDictionary<string, any>;
390390
const levels = ['log', 'debug', 'info', 'warning', 'error', 'fatal'];
391391

392392
if (processed) {

0 commit comments

Comments
 (0)