Skip to content

Add categorizable code to Error.GenericError - #208

Merged
aleksandar-apostolov merged 2 commits into
developfrom
feature/and-1366-generic-error-code
Aug 6, 2026
Merged

Add categorizable code to Error.GenericError#208
aleksandar-apostolov merged 2 commits into
developfrom
feature/and-1366-generic-error-code

Conversation

@aleksandar-apostolov

@aleksandar-apostolov aleksandar-apostolov commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Goal

Closes AND-1366 — add a machine-readable code to Error.GenericError so 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

  • Add a code: Int to Error.GenericError, defaulting to GenericError.UNCATEGORIZED (0). It is set by the SDK at construction via a new public secondary constructor GenericError(message, code); the setter is private.
  • Implemented as a body property, not a primary-constructor parameter, so the change is additive and binary-backward-compatible: the primary constructor, copy(), componentN, and equals/hashCode/toString are unchanged, and no new Error subtype is introduced (consumer exhaustive when still compiles). API dumps regenerated — additions only.
  • Error.copyWithMessage() now preserves code; the generated copy() 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.
  • No unit tests: the :stream-result module has no test source set. The copy()-drops-code behaviour will be pinned by a test on the Chat side under AND-1367.

@aleksandar-apostolov
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
aleksandar-apostolov force-pushed the feature/and-1366-generic-error-code branch from 30b5750 to 7f165eb Compare August 6, 2026 10:44
Comment thread stream-result/src/commonMain/kotlin/io/getstream/result/Error.kt Outdated
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.
@aleksandar-apostolov
aleksandar-apostolov merged commit 7cb1a38 into develop Aug 6, 2026
4 checks passed
@aleksandar-apostolov
aleksandar-apostolov deleted the feature/and-1366-generic-error-code branch August 6, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants