Repository navigation
fix: report exception types instead of error codes - #124
NikitaKurpas wants to merge 5 commits into
Conversation
|
|
| public var type: String { | ||
| String(code) | ||
| let error = self as Error | ||
| return Swift.type(of: error) == NSError.self ? domain : String(describing: Swift.type(of: error)) |
There was a problem hiding this comment.
exception.type is supposed to be the fully qualified type name, like MyApp.ServiceA.Failure. String(describing:) only keeps the last piece, so ServiceA.Failure and ServiceB.Failure both show up as "Failure".
PostHog can get away with the short name because it also sends the module separately. We only have exception.type, so the qualified name has to go there.
Could we use String(reflecting:) and, when the dynamic type is NSError, keep using domain? That covers URLError and plain NSError, whose useful name is the domain (NSURLErrorDomain).
One cleanup: for private and function-local errors, String(reflecting:) includes an address, (unknown context at $…), that changes every app launch. Strip that part so the same error does not look new on every run.
@nachoBonafonte @bryce-b any inputs here?
There was a problem hiding this comment.
I started with String(reflecting:) but decided to go with String(describing:) 😅
Reverted that, now it uses String(reflecting:).
There was a problem hiding this comment.
One cleanup: for private and function-local errors,
String(reflecting:)includes an address,(unknown context at $…), that changes every app launch.
TIL. Removed the (unknown context at $…) part.
|
Hi, this repository is on hold, so no more PRs here, there is already a PR on the main library open telemetry-swift to move all the core code there: 1220. This PR should be created there once the 1220 PR is merged. |
exception.typecurrently contains a numeric error code. Codes do not identify the error type and can mean different things in different domains. When no custom localized description is supplied, Foundation already includes the code in the defaultlocalizedDescription.Report the fully qualified Swift error type using
String(reflecting:), falling back to the domain for plainNSError. Casting back toErrorbefore reading its dynamic type preserves bridged Swift error types. Qualified names distinguish errors with the same short name in different modules or enclosing types.