-
-
Notifications
You must be signed in to change notification settings - Fork 348
Cannot subclass User
any more
#5079
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
Comments
Hi @DarkDust, thanks for raising this issue. I do not think that it was intended that SentryUser is to be subclassed, but maybe @philipphofmann can share some insights on that. Did you try wrap the |
No, I just added a convenience initializer to |
@DarkDust that is of course unintended and unfortunate, as we usually try for that not to happen. |
Ahh, sorry, that's an unfortunate side effect of adding Codable via Swift extensions that I totally missed when adding the implementation. @DarkDust, do you have a workaround? We must investigate if we can somehow fix this, but my hopes aren't high. |
@philipphofmann: I guess the only real solution is to port
The important part is |
We should be able to fix this by adding extra subclasses for the decodable implementations similar to what we did for SentryEvent sentry-cocoa/Sources/Sentry/Public/SentryEvent.h Lines 199 to 217 in 4c5c48c
Ideally, we add these classes in Swift and make them internal. |
I again looked into this, and adding all these subclasses increases the SDK size and the complexity of our decoable Swift code. While strictly speaking this is a breaking change, the affected classes aren't meant to be subclassed anyways and there is an easy workaround to solve the problem. I added an entry to the troubleshooting guide getsentry/sentry-docs#13509. We can revisit this decision if more people come up with good use cases for subclassing such classes. |
Platform
macOS
Environment
Production
Installed
CocoaPods
Version
8.49.0
Xcode Version
16.2
Did it work on previous versions?
8.41.0
Steps to Reproduce
We have a subclass of
Sentry.User
with additional informations. Due to the addition of theCodable
support in a recent version of the Sentry SDK, this subclass cannot be used any more. The Swift compiler complains:However, we cannot provide it, either, since then Swift complains:
Code to reproduce:
Expected Result
Existing subclass of
User
should still compile.Actual Result
We were able to work around this problem by using a convenience initializer, but lost the ability to provide additional informations.
As far as I can see, the only real solution would be to port the whole
User
class to Swift and have the codable implementation in the main class instead of an extension:This way subclasses are able to override the decoding initializer.
Are you willing to submit a PR?
maybe
The text was updated successfully, but these errors were encountered: