Add categorizable code to Error.GenericError - #208
Merged
aleksandar-apostolov merged 2 commits intoAug 6, 2026
Conversation
aleksandar-apostolov
marked this pull request as ready for review
August 6, 2026 10:41
Add a machine-readable `code: Int` to `Error.GenericError` so callers can branch on the kind of error without matching the message string. Implemented as a body property with a public secondary constructor and a private setter, keeping the change additive: the primary constructor, copy(), componentN, equals/hashCode/toString are unchanged, so it stays binary-backward-compatible (API dumps regenerated, additions only). copyWithMessage() now preserves the code; the generated copy() does not (documented on the property).
aleksandar-apostolov
force-pushed
the
feature/and-1366-generic-error-code
branch
from
August 6, 2026 10:44
30b5750 to
7f165eb
Compare
gpunto
approved these changes
Aug 6, 2026
Manually implement equals/hashCode/toString on GenericError so the body-property `code` is reflected in them (the generated versions ignore non-constructor properties). Matches the existing manual implementations on ThrowableError/NetworkError. No public API change (identical signatures). copy() still does not carry code — inherent to data classes. Addresses review feedback on #208.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Closes AND-1366 — add a machine-readable code to
Error.GenericErrorso callers can categorize errors without matching the message string.Unblocks stream-chat-android AND-1367 (distinguish an empty token from a genuine user_id mismatch at connect), reported by Bumble.
Implementation
code: InttoError.GenericError, defaulting toGenericError.UNCATEGORIZED(0). It is set by the SDK at construction via a new public secondary constructorGenericError(message, code); the setter is private.copy(),componentN, andequals/hashCode/toStringare unchanged, and no newErrorsubtype is introduced (consumer exhaustivewhenstill compiles). API dumps regenerated — additions only.Error.copyWithMessage()now preservescode; the generatedcopy()does not (documented on the property).Testing
./gradlew :stream-result:apiDump— regenerates the API dumps; diff is additive only (new secondary constructor,getCode(), companion +UNCATEGORIZED), no existing signature changed../gradlew :stream-result:spotlessCheck— passes.:stream-resultmodule has no test source set. Thecopy()-drops-codebehaviour will be pinned by a test on the Chat side under AND-1367.