Skip to content

All errors via chat error #331

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

Open
wants to merge 1 commit into
base: 321-soft-deletes-and-validation-loosening
Choose a base branch
from

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Jul 13, 2025

Closes #301

Summary by CodeRabbit

  • New Features

    • Introduced a specific error message when a client ID is missing, guiding users to initialize their Realtime instance with a client ID.
  • Bug Fixes

    • Improved consistency and clarity of error handling related to missing client IDs during chat operations.

Copy link

coderabbitai bot commented Jul 13, 2025

Walkthrough

The changes introduce a dedicated clientIdRequired error case in the internal error handling system, updating all relevant code paths to throw this specific ChatError instead of a generic custom error code. This ensures that errors related to missing clientId consistently use the new error case throughout the codebase.

Changes

File(s) Change Summary
Sources/AblyChat/Errors.swift Added clientIdRequired case to error enums, updated error code/status mapping, and descriptions
Sources/AblyChat/ChatAPI.swift, Updated error thrown for missing clientId to use ChatError.clientIdRequired
Sources/AblyChat/Room.swift Updated error thrown for missing clientId to use ChatError.clientIdRequired

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ChatAPI
    participant Errors

    Client->>ChatAPI: sendMessage() / updateMessage() / Room init
    ChatAPI->>ChatAPI: Check if realtime.clientId is present
    alt clientId is missing
        ChatAPI->>Errors: throw ChatError.clientIdRequired
    else clientId is present
        ChatAPI->>ChatAPI: Proceed with operation
    end
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
All thrown errors go via ChatError (#301)

Suggested reviewers

  • lawrence-forooghian
  • umair-ably

Poem

A hop and a skip, a bug we did find,
Missing client IDs—oh, what a bind!
Now errors are tidy, with reasons so clear,
Through ChatError they travel, no need to fear.
With every new case, our code’s more refined,
The chat’s now robust, and the bunnies don’t mind! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c46c08 and 2bd6023.

📒 Files selected for processing (3)
  • Sources/AblyChat/ChatAPI.swift (2 hunks)
  • Sources/AblyChat/Errors.swift (7 hunks)
  • Sources/AblyChat/Room.swift (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: maratal
PR: ably/ably-chat-swift#165
File: Sources/AblyChat/Reaction.swift:14-14
Timestamp: 2024-12-10T01:59:02.065Z
Learning: For the 'ably-chat-swift' repository, documentation-only PRs should focus exclusively on public methods and properties. Avoid suggesting changes to internal comments or private methods in such PRs.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/SubscriptionAsyncSequence.swift:36-41
Timestamp: 2025-06-29T16:02:43.988Z
Learning: In the AblyChat Swift codebase, the fatalError in SubscriptionAsyncSequence.swift's mock async sequence handling (around line 39) is intentional and should not be flagged. This fatalError catches programmer errors when a throwing AsyncSequence is incorrectly passed to the mock initializer, which is meant for testing/development purposes.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/ContentView.swift:94-99
Timestamp: 2025-06-14T21:47:20.509Z
Learning: In the Ably Chat Swift example app, using fatalError for missing clientID is intentional and appropriate since it represents a programmer error rather than a recoverable runtime condition. The clientID is considered an essential configuration requirement.
Sources/AblyChat/Room.swift (5)
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/ContentView.swift:94-99
Timestamp: 2025-06-14T21:47:20.509Z
Learning: In the Ably Chat Swift example app, using fatalError for missing clientID is intentional and appropriate since it represents a programmer error rather than a recoverable runtime condition. The clientID is considered an essential configuration requirement.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/Mocks/MockRealtime.swift:348-384
Timestamp: 2025-06-14T16:19:29.327Z
Learning: The MockRealtime class in Example/AblyChatExample/Mocks/MockRealtime.swift is specifically for example app construction, not for testing. The actual test mocks are located in the Tests directory. If example app mocks are unused, fatalError calls are appropriate to catch accidental usage.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Tests/AblyChatTests/Mocks/MockRealtime.swift:41-47
Timestamp: 2025-06-14T15:18:17.427Z
Learning: In the MockRealtime class in Tests/AblyChatTests/Mocks/MockRealtime.swift, the body parameter in the request method is constrained to dictionary or array types, but currently only dictionary types are used. Arrays are not yet used for this method, so the current implementation assumes dictionary-only for simplicity.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/DefaultOccupancy.swift:10-13
Timestamp: 2025-05-12T21:01:14.109Z
Learning: The `Occupancy` protocol in the Ably Chat Swift SDK is annotated with `@MainActor`, making all conforming types like `DefaultOccupancy` automatically main actor-isolated without requiring explicit annotations on their methods.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/SubscriptionAsyncSequence.swift:36-41
Timestamp: 2025-06-29T16:02:43.988Z
Learning: In the AblyChat Swift codebase, the fatalError in SubscriptionAsyncSequence.swift's mock async sequence handling (around line 39) is intentional and should not be flagged. This fatalError catches programmer errors when a throwing AsyncSequence is incorrectly passed to the mock initializer, which is meant for testing/development purposes.
Sources/AblyChat/ChatAPI.swift (7)
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/ContentView.swift:94-99
Timestamp: 2025-06-14T21:47:20.509Z
Learning: In the Ably Chat Swift example app, using fatalError for missing clientID is intentional and appropriate since it represents a programmer error rather than a recoverable runtime condition. The clientID is considered an essential configuration requirement.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Tests/AblyChatTests/Mocks/MockRealtime.swift:41-47
Timestamp: 2025-06-14T15:18:17.427Z
Learning: In the MockRealtime class in Tests/AblyChatTests/Mocks/MockRealtime.swift, the body parameter in the request method is constrained to dictionary or array types, but currently only dictionary types are used. Arrays are not yet used for this method, so the current implementation assumes dictionary-only for simplicity.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Example/AblyChatExample/Mocks/MockClients.swift:0-0
Timestamp: 2025-05-16T21:04:26.244Z
Learning: In the ably-chat-swift project, mock implementations (like those in MockClients.swift) are intentionally kept simple, sometimes omitting parameter-based filtering behavior for testing simplicity.
Learnt from: maratal
PR: ably/ably-chat-swift#165
File: Sources/AblyChat/Reaction.swift:14-14
Timestamp: 2024-12-10T01:59:02.065Z
Learning: For the 'ably-chat-swift' repository, documentation-only PRs should focus exclusively on public methods and properties. Avoid suggesting changes to internal comments or private methods in such PRs.
Learnt from: maratal
PR: ably/ably-chat-swift#165
File: docs-coverage-report:5-8
Timestamp: 2024-12-10T01:59:12.404Z
Learning: In the AblyChat Swift project, documentation coverage should focus on public methods and properties. Private and internal entities do not require documentation.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/SubscriptionAsyncSequence.swift:36-41
Timestamp: 2025-06-29T16:02:43.988Z
Learning: In the AblyChat Swift codebase, the fatalError in SubscriptionAsyncSequence.swift's mock async sequence handling (around line 39) is intentional and should not be flagged. This fatalError catches programmer errors when a throwing AsyncSequence is incorrectly passed to the mock initializer, which is meant for testing/development purposes.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/Mocks/MockRealtime.swift:348-384
Timestamp: 2025-06-14T16:19:29.327Z
Learning: The MockRealtime class in Example/AblyChatExample/Mocks/MockRealtime.swift is specifically for example app construction, not for testing. The actual test mocks are located in the Tests directory. If example app mocks are unused, fatalError calls are appropriate to catch accidental usage.
Sources/AblyChat/Errors.swift (5)
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/ContentView.swift:94-99
Timestamp: 2025-06-14T21:47:20.509Z
Learning: In the Ably Chat Swift example app, using fatalError for missing clientID is intentional and appropriate since it represents a programmer error rather than a recoverable runtime condition. The clientID is considered an essential configuration requirement.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Sources/AblyChat/SubscriptionAsyncSequence.swift:36-41
Timestamp: 2025-06-29T16:02:43.988Z
Learning: In the AblyChat Swift codebase, the fatalError in SubscriptionAsyncSequence.swift's mock async sequence handling (around line 39) is intentional and should not be flagged. This fatalError catches programmer errors when a throwing AsyncSequence is incorrectly passed to the mock initializer, which is meant for testing/development purposes.
Learnt from: maratal
PR: ably/ably-chat-swift#165
File: docs-coverage-report:5-8
Timestamp: 2024-12-10T01:59:12.404Z
Learning: In the AblyChat Swift project, documentation coverage should focus on public methods and properties. Private and internal entities do not require documentation.
Learnt from: maratal
PR: ably/ably-chat-swift#286
File: Example/AblyChatExample/Mocks/MockClients.swift:0-0
Timestamp: 2025-05-16T21:04:26.244Z
Learning: In the ably-chat-swift project, mock implementations (like those in MockClients.swift) are intentionally kept simple, sometimes omitting parameter-based filtering behavior for testing simplicity.
Learnt from: maratal
PR: ably/ably-chat-swift#293
File: Example/AblyChatExample/MessageViews/MessageReactionsSheet.swift:15-31
Timestamp: 2025-06-14T16:18:47.038Z
Learning: In the AblyChat Swift SDK, there are three message reaction types: unique (one reaction per client per message), distinct (one reaction of each type per client per message), and multiple (any number of reactions including repeats, with counts). The MessageReactionsSheet specifically handles unique/distinct reactions where the count is always 1 per client per emoji. Only the "multiple" reaction type would have accumulating counts.
🧬 Code Graph Analysis (1)
Sources/AblyChat/ChatAPI.swift (1)
Sources/AblyChat/InternalError.swift (6)
  • toInternalError (41-43)
  • toInternalError (47-49)
  • toInternalError (53-55)
  • toInternalError (59-61)
  • toInternalError (65-67)
  • toInternalError (71-73)
🔇 Additional comments (10)
Sources/AblyChat/Errors.swift (7)

66-66: Well-structured addition of the new error case.

The clientIdRequired case is properly added to the CaseThatImpliesFixedStatusCode enum, maintaining consistency with the existing error handling pattern.


90-91: Correct mapping to .badRequest error code.

The mapping of clientIdRequired to .badRequest is appropriate, as missing client ID is a client configuration issue that should result in a 40000 error code.


105-106: Appropriate HTTP status code assignment.

The 400 status code is correctly assigned for the clientIdRequired error, following the established pattern for client configuration errors.


177-177: Consistent addition to the main ChatError enum.

The new error case is properly added to the ChatError enum, maintaining the systematic approach to error handling.


210-211: Correct error code and status code mapping.

The mapping to .fixedStatusCode(.clientIdRequired) correctly links the new error case to its corresponding code and status.


266-267: Clear and instructive error message.

The localized description provides clear guidance to developers on how to resolve the missing client ID issue.


288-289: Appropriate cause handling.

The clientIdRequired error case correctly returns nil for the cause, as this is a configuration issue without an underlying error.

Sources/AblyChat/Room.swift (1)

268-268: Excellent standardization of client ID error handling.

The change from a custom error creation to using the standardized clientIdRequired error case improves consistency across the codebase. The error semantics remain the same while leveraging the centralized error definition.

Sources/AblyChat/ChatAPI.swift (2)

71-71: Consistent standardization in sendMessage method.

The change to use the standardized clientIdRequired error case improves consistency and maintainability. The error handling pattern aligns with the broader codebase changes.


109-109: Consistent standardization in updateMessage method.

The change to use the standardized clientIdRequired error case maintains consistency with the sendMessage method and other parts of the codebase.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 301-all-errors-via-ChatError

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@maratal maratal changed the base branch from main to 321-soft-deletes-and-validation-loosening July 13, 2025 22:10
@github-actions github-actions bot temporarily deployed to staging/pull/331/AblyChat July 13, 2025 22:11 Inactive
@maratal maratal force-pushed the 321-soft-deletes-and-validation-loosening branch 4 times, most recently from 24f4aa2 to 4539d1a Compare July 14, 2025 13:57
@maratal maratal force-pushed the 301-all-errors-via-ChatError branch from 8e4aec3 to 291152b Compare July 14, 2025 15:27
@github-actions github-actions bot temporarily deployed to staging/pull/331/AblyChat July 14, 2025 15:28 Inactive
@maratal maratal force-pushed the 321-soft-deletes-and-validation-loosening branch from 4539d1a to 7092f9a Compare July 14, 2025 17:00
@maratal maratal force-pushed the 301-all-errors-via-ChatError branch from 291152b to 114807a Compare July 14, 2025 17:03
@github-actions github-actions bot temporarily deployed to staging/pull/331/AblyChat July 14, 2025 17:04 Inactive
@maratal maratal force-pushed the 321-soft-deletes-and-validation-loosening branch from 7092f9a to 7c46c08 Compare July 14, 2025 17:05
@maratal
Copy link
Collaborator Author

maratal commented Jul 14, 2025

See this comment re fails

@maratal maratal marked this pull request as ready for review July 14, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Make all thrown errors go via ChatError
1 participant