Skip to content

Fall back to DTO path on direct adapter failure#6489

Open
VelikovPetar wants to merge 1 commit into
v6from
bug/direct-event-parser-fallback_v6
Open

Fall back to DTO path on direct adapter failure#6489
VelikovPetar wants to merge 1 commit into
v6from
bug/direct-event-parser-fallback_v6

Conversation

@VelikovPetar
Copy link
Copy Markdown
Contributor

@VelikovPetar VelikovPetar commented Jun 3, 2026

Goal

Harden the opt-in fast event parser so a thrown direct-adapter exception degrades gracefully to the existing DTO path instead of failing the whole event parse. Also clean up a dead Date(0) fallback flagged by SonarCloud. Ports two fixes from develop PR #6473 back to V6.

Implementation

  • DirectEventParser.parse: wrap adapter.fromJson(raw) in runCatching. On failure, log at verbose level and return nullMoshiChatParser.parseAndProcessEvent already checks for null and falls through to the DTO path.
  • NewMessageEventAdapter: drop the ?: Date(0) elvis on the createdAt constructor argument. The explicit if (createdAt == null) throw JsonDataException(...) above already guarantees createdAt is non-null at that point, so the elvis was dead.

The malformed-created_at guards (missing field, explicit JSON null, unparseable string) are preserved unchanged.

UI Changes

No UI changes.

Testing

  • Existing DirectEventParserTest, NewMessageEventParsingTest, and other parser2 unit tests continue to pass.
  • Fallback behavior can be exercised by feeding a JSON payload that triggers an adapter exception (e.g., malformed nested object on a supported event type) — the parser should return null and the DTO path should take over.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced event parsing error handling to gracefully manage malformed data instead of crashing the application. The system now includes improved diagnostic logging and safe fallback mechanisms.
    • Improved message event timestamp accuracy by ensuring proper date initialization instead of using default fallback values.

Co-Authored-By: Claude <noreply@anthropic.com>
@VelikovPetar VelikovPetar added the pr:bug Bug fix label Jun 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled (or ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@VelikovPetar VelikovPetar marked this pull request as ready for review June 3, 2026 12:03
@VelikovPetar VelikovPetar requested a review from a team as a code owner June 3, 2026 12:03
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 72330dfb-c605-42df-975a-efc5dc3409a0

📥 Commits

Reviewing files that changed from the base of the PR and between 2c3b9f7 and 4ecea5e.

📒 Files selected for processing (2)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/DirectEventParser.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/direct/NewMessageEventAdapter.kt

Walkthrough

This PR improves event parsing robustness in Stream Chat Android. The direct event parser now catches adapter parsing failures, logs them, and falls back to null for DTO parsing. The NewMessageEventAdapter removes a contradictory default fallback for createdAt to ensure consistency with prior validation.

Changes

Event Parsing Robustness

Layer / File(s) Summary
Direct parser exception handling
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/DirectEventParser.kt
DirectEventParser.parse(raw) now wraps adapter parsing in runCatching, logs verbose messages with event type and exception details on failure, and returns null to allow callers to fall back to DTO parsing instead of propagating exceptions.
Message event timestamp handling
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/direct/NewMessageEventAdapter.kt
NewMessageEventAdapter.fromJson no longer defaults createdAt to Date(0) when null; it assigns the parsed non-null createdAt directly, aligning with validation that requires created_at to be present and parseable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 With gentle hands we catch the falls,
When parsing whispers through the walls,
A log, a null, a fallback way—
The messages now dance and stay!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fall back to DTO path on direct adapter failure' clearly and concisely summarizes the main change—adding fallback behavior when the direct adapter fails.
Description check ✅ Passed The description includes all required template sections: Goal, Implementation, UI Changes, Testing, and contributor/reviewer checklists are acknowledged.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/direct-event-parser-fallback_v6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VelikovPetar VelikovPetar added pr:improvement Improvement and removed pr:bug Bug fix labels Jun 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.30 MB 0.04 MB 🟢
stream-chat-android-offline 5.49 MB 5.52 MB 0.03 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.72 MB 0.07 MB 🟢
stream-chat-android-compose 12.87 MB 12.91 MB 0.05 MB 🟢

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 3, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:improvement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant