-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
Fix: SentryOptions initWithDict return nil for error #2679
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
==========================================
+ Coverage 78.90% 80.69% +1.79%
==========================================
Files 249 247 -2
Lines 23091 22869 -222
Branches 10037 10129 +92
==========================================
+ Hits 18219 18455 +236
+ Misses 4390 3960 -430
+ Partials 482 454 -28
Continue to review full report at Codecov.
|
What is the motivation for this change, @brustolin? Could you please fill out the PR template? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some comments!
NSString *dsn = @""; | ||
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) { | ||
dsn = options[@"dsn"]; | ||
} | ||
if (options[@"dsn"] != [NSNull null]) { | ||
NSString *dsn = @""; | ||
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) { | ||
dsn = options[@"dsn"]; | ||
} | ||
|
||
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error]; | ||
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error]; | ||
if (self.parsedDsn == nil) { | ||
return NO; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand why the test case flips from asserting the DSN is not nil to asserting that it is nil in the default case. Do we allow initializing the SDK without a valid DSN? If not, I think it would be clearer what the eventual outcome would be here if instead, we made this an early return like so:
if (options[@"dsn"] == [NSNull null]) {
return NO;
}
and then do the rest of the work at one level higher of scope below that. It would also avoid all the work below being done which wouldn't matter if the SDK winds up in an error state anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case flipped because the prior assumption was wrong.
Why we allow options to be initialized without a DSN I dont know , maybe @philipphofmann can give us some context here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can initialize the SDK without a DSN. The SDK would run and do its job, but the client will drop everything see
sentry-cocoa/Sources/Sentry/SentryClient.m
Lines 636 to 639 in 72c650a
- (BOOL)isDisabled | |
{ | |
return !_isEnabled || !self.options.enabled || nil == self.options.parsedDsn; | |
} |
It's similar to using options.enabled = false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened an issue where we can discuss this further, since it's out of scope for this PR: #2712
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add one test as pointed out, LGTM.
I think we could also remove didFailWithError:(NSError *_Nullable *_Nullable)error
from SentryOptions.initWithDict
. Could you check the hybrid SDKs if they use it, and if not remove it in another PR, @brustolin?
NSString *dsn = @""; | ||
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) { | ||
dsn = options[@"dsn"]; | ||
} | ||
if (options[@"dsn"] != [NSNull null]) { | ||
NSString *dsn = @""; | ||
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) { | ||
dsn = options[@"dsn"]; | ||
} | ||
|
||
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error]; | ||
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error]; | ||
if (self.parsedDsn == nil) { | ||
return NO; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can initialize the SDK without a DSN. The SDK would run and do its job, but the client will drop everything see
sentry-cocoa/Sources/Sentry/SentryClient.m
Lines 636 to 639 in 72c650a
- (BOOL)isDisabled | |
{ | |
return !_isEnabled || !self.options.enabled || nil == self.options.parsedDsn; | |
} |
It's similar to using options.enabled = false
.
RN and Unity use it. |
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
4977fbc | 1231.55 ms | 1239.80 ms | 8.25 ms |
7fb7afb | 1230.12 ms | 1251.04 ms | 20.92 ms |
8cb9355 | 1225.23 ms | 1231.22 ms | 5.99 ms |
f8fc36d | 1226.31 ms | 1247.80 ms | 21.49 ms |
443723a | 1205.24 ms | 1220.52 ms | 15.28 ms |
b6ba04e | 1217.45 ms | 1248.92 ms | 31.47 ms |
005bb4c | 1237.38 ms | 1255.54 ms | 18.16 ms |
4259afd | 1234.04 ms | 1256.76 ms | 22.72 ms |
ecd9ecd | 1215.77 ms | 1238.70 ms | 22.93 ms |
d413317 | 1203.27 ms | 1215.02 ms | 11.75 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
4977fbc | 20.76 KiB | 419.86 KiB | 399.10 KiB |
7fb7afb | 20.76 KiB | 419.70 KiB | 398.94 KiB |
8cb9355 | 20.76 KiB | 419.70 KiB | 398.95 KiB |
f8fc36d | 20.76 KiB | 419.70 KiB | 398.94 KiB |
443723a | 20.76 KiB | 414.44 KiB | 393.68 KiB |
b6ba04e | 20.76 KiB | 414.45 KiB | 393.69 KiB |
005bb4c | 20.76 KiB | 419.70 KiB | 398.94 KiB |
4259afd | 20.76 KiB | 419.70 KiB | 398.94 KiB |
ecd9ecd | 20.76 KiB | 420.23 KiB | 399.47 KiB |
d413317 | 20.76 KiB | 420.71 KiB | 399.95 KiB |
📜 Description
Changed [SentryOptions initWithDict:error:] to return nil if an error occurs even if no error argument is provided.
Before this, it only returned nil if and error argument was provided.
💡 Motivation and Context
According to Apple's documentation on how to deal with error we see this:
When using
SentryOptions initWithDict:error:
with Unity, we found out that it did not fail when the DSN was invalid. Thats because Unity code cant use an error reference and needs to rely solely on the initialization result.Also, relying only on the error reference value can be misleading because it may be used in multiple calls and have 'dirty' value.
💚 How did you test it?
Unit tests
📝 Checklist
sendDefaultPII
is enabled.#skip-changelog