Skip to content

Commit eaa359e

Browse files
fix: No reason for NSException (#6653)
Send no exception value when the NSException has no reason. Fixes GH-3706
1 parent a4e1541 commit eaa359e

File tree

4 files changed

+135
-7
lines changed

4 files changed

+135
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- Remove `getHash` from SentryDsn (#6605)
3333
- The precompiled XCFramework is now built with Xcode 16. To submit to the App Store, [Apple now requires Xcode 16](https://developer.apple.com/news/upcoming-requirements/?id=02212025a).
3434
If you need a precompiled XCFramework built with Xcode 15, continue using Sentry SDK 8.x.x.
35+
- Set `SentryException.type` to `nil` when `NSException` has no `reason` (#6653). The backend then can provide a proper message when there is no reason.
3536

3637
### Features
3738

Sources/Sentry/SentryCrashReportConverter.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,17 @@ - (SentryDebugMeta *)debugMetaFromBinaryImageDictionary:(NSDictionary *)sourceIm
482482

483483
- (SentryException *)parseNSException
484484
{
485-
NSString *reason = @"";
486-
if (nil != self.exceptionContext[@"nsexception"][@"reason"]) {
485+
NSString *reason = nil;
486+
if (self.exceptionContext[@"nsexception"][@"reason"] != nil) {
487487
reason = self.exceptionContext[@"nsexception"][@"reason"];
488-
} else if (nil != self.exceptionContext[@"reason"]) {
488+
} else if (self.exceptionContext[@"reason"] != nil) {
489489
reason = self.exceptionContext[@"reason"];
490490
}
491491

492-
return [[SentryException alloc] initWithValue:[NSString stringWithFormat:@"%@", reason]
493-
type:self.exceptionContext[@"nsexception"][@"name"]
494-
?: @"NSException"]; // The fallback value is best-attempt in case the exception name is
495-
// not available
492+
// The fallback value is best-attempt in case the exception name is not available
493+
NSString *type = self.exceptionContext[@"nsexception"][@"name"] ?: @"NSException";
494+
495+
return [[SentryException alloc] initWithValue:reason type:type];
496496
}
497497

498498
- (void)enhanceValueFromNotableAddresses:(SentryException *)exception
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"report": {
3+
"version": "3.2.0",
4+
"id": "BEBB7B2D-E4F8-4ED2-BB7F-FCF04F6282AE",
5+
"process_name": null,
6+
"timestamp": 1716459692,
7+
"type": "standard"
8+
},
9+
"process": {},
10+
"system": {
11+
"system_name": null,
12+
"system_version": null,
13+
"machine": null,
14+
"model": null,
15+
"kernel_version": null,
16+
"os_version": null,
17+
"jailbroken": false,
18+
"app_start_time": null,
19+
"CFBundleExecutablePath": null,
20+
"CFBundleExecutable": null,
21+
"CFBundleIdentifier": null,
22+
"CFBundleName": null,
23+
"CFBundleVersion": null,
24+
"CFBundleShortVersionString": null,
25+
"app_uuid": null,
26+
"cpu_arch": null,
27+
"cpu_type": 0,
28+
"cpu_subtype": 0,
29+
"binary_cpu_type": 0,
30+
"binary_cpu_subtype": 0,
31+
"process_name": null,
32+
"process_id": 0,
33+
"parent_process_id": 0,
34+
"device_app_hash": null,
35+
"build_type": null,
36+
"memory": {
37+
"size": 0,
38+
"usable": 0,
39+
"free": 0
40+
},
41+
"application_stats": {
42+
"application_active": false,
43+
"application_in_foreground": true,
44+
"launches_since_last_crash": 1,
45+
"sessions_since_last_crash": 1,
46+
"active_time_since_last_crash": 0,
47+
"background_time_since_last_crash": 0,
48+
"sessions_since_launch": 1,
49+
"active_time_since_launch": 0,
50+
"background_time_since_launch": 0
51+
}
52+
},
53+
"crash": {
54+
"error": {
55+
"mach": {
56+
"exception": 10,
57+
"exception_name": "EXC_CRASH",
58+
"code": 0,
59+
"subcode": 0
60+
},
61+
"signal": {
62+
"signal": 6,
63+
"name": "SIGABRT",
64+
"code": 0
65+
},
66+
"address": 0,
67+
"type": "nsexception",
68+
"nsexception": {
69+
"name": "MyCustomException",
70+
"userInfo": "{\n detail = \"Additional information\";\n}"
71+
}
72+
}
73+
},
74+
"sentry_sdk_scope": {
75+
"breadcrumbs": []
76+
},
77+
"user": {
78+
"context": {
79+
"app": {
80+
"app_build": "1",
81+
"app_id": "0B84C76D-16DE-3EE2-85B1-E93FA7080DFA",
82+
"app_identifier": "io.sentry.macOS-Swift",
83+
"app_name": "macOS-Swift",
84+
"app_start_time": "2024-05-23T10:21:30Z",
85+
"app_version": "1.0",
86+
"build_type": "unknown",
87+
"device_app_hash": "2a5fab9e6e92e8fb0bccda61214e76d9a1eeb751"
88+
},
89+
"device": {
90+
"arch": "arm64",
91+
"family": "macOS",
92+
"free_memory": 2408169472,
93+
"locale": "en_AT",
94+
"memory_size": 68719476736,
95+
"model": "Mac14,5",
96+
"simulator": false,
97+
"usable_memory": 61236002816
98+
},
99+
"os": {
100+
"build": "23E224",
101+
"kernel_version": "Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020",
102+
"name": "macOS",
103+
"rooted": false,
104+
"version": "14.4.1"
105+
}
106+
},
107+
"release": "[email protected]+1",
108+
"user": {
109+
"email": "[email protected]"
110+
}
111+
},
112+
"debug": {}
113+
}

Tests/SentryTests/SentryCrashReportConverterTests.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ - (void)testUnknownTypeException
227227
[self isValidReport:@"Resources/UnknownTypeException"];
228228
}
229229

230+
- (void)testNSExceptionWithoutReason
231+
{
232+
[self isValidReport:@"Resources/NSExceptionWithoutReason"];
233+
234+
NSDictionary *rawCrash = [self getCrashReport:@"Resources/NSExceptionWithoutReason"];
235+
SentryCrashReportConverter *reportConverter =
236+
[[SentryCrashReportConverter alloc] initWithReport:rawCrash inAppLogic:self.inAppLogic];
237+
SentryEvent *event = [reportConverter convertReportToEvent];
238+
239+
SentryException *exception = event.exceptions.firstObject;
240+
XCTAssertEqualObjects(exception.type, @"MyCustomException");
241+
XCTAssertNil(exception.value);
242+
}
243+
230244
- (void)testStackoverflow
231245
{
232246
[self isValidReport:@"Resources/StackOverflow"];

0 commit comments

Comments
 (0)