Skip to content
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

Fix error code when fetching room with inconsistent options #187

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Dec 10, 2024

I should have done this in e7612c9.

The 40000 error code does not have a name in the spec or in the JS Chat SDK, so nonspecificUserError is my invention.

Summary by CodeRabbit

  • Bug Fixes

    • Updated error handling to categorize mismatched room options under a new error type, nonspecificUserError, instead of the previous inconsistentRoomOptions.
  • Tests

    • Modified test cases to reflect the new error categorization for mismatched room options.

Copy link

coderabbitai bot commented Dec 10, 2024

Warning

Rate limit exceeded

@lawrence-forooghian has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6dbb93d and 1756aa3.

📒 Files selected for processing (2)
  • Sources/AblyChat/Errors.swift (5 hunks)
  • Tests/AblyChatTests/DefaultRoomsTests.swift (2 hunks)

Walkthrough

The changes in this pull request involve significant updates to the ErrorCode enumeration in the Errors.swift file of the Ably Chat SDK. The inconsistentRoomOptions case has been removed and replaced with a new case, nonspecificUserError, which carries a different integer value. This modification affects related enumerations and methods, including CaseThatImpliesFixedStatusCode and ChatError, ensuring consistent error handling across the SDK. Additionally, corresponding test methods in DefaultRoomsTests.swift have been updated to reflect these changes in error categorization.

Changes

File Change Summary
Sources/AblyChat/Errors.swift - Removed case inconsistentRoomOptions from ErrorCode.
- Added case nonspecificUserError = 40000 to ErrorCode.
- Updated CaseThatImpliesFixedStatusCode to use nonspecificUserError.
- Modified toNumericErrorCode and codeAndStatusCode methods to reflect the new error case.
Tests/AblyChatTests/DefaultRoomsTests.swift - Updated test methods to expect nonspecificUserError instead of inconsistentRoomOptions for error assertions.

Possibly related PRs

  • [ECO-5144] Implement CHA-PR3h etc #163: This PR modifies error handling in the DefaultMessages class and introduces changes to the ErrorCode enum, which are directly related to the changes made in the main PR regarding the ErrorCode enumeration and its cases.
  • [ECO-5148] Implement “async room get” spec points #171: This PR adds a new error case to the ErrorCode enum and updates the ChatError enum, which aligns with the modifications in the main PR that also involve changes to the ErrorCode and ChatError enumerations.

Suggested reviewers

  • umair-ably
  • maratal

🐇 In the world of code, where errors may roam,
A new case was born, to find a new home.
From options once tangled, now clear as the sky,
Nonspecific user errors, we bid the old bye.
With tests now aligned, our paths are made bright,
In the realm of Ably, all errors feel right! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
Sources/AblyChat/Errors.swift (1)

14-15: Consider adding more specific error codes for different user error scenarios.

While the introduction of nonspecificUserError (40000) provides a general error category, it might be too broad. Consider creating more specific error codes for different user error scenarios to help with debugging and error handling.

public enum ErrorCode: Int {
    /// The user attempted to perform an invalid action.
    case nonspecificUserError = 40000
+   /// The user attempted to get a room with inconsistent options.
+   case inconsistentRoomOptionsError = 40001
+   /// The user attempted an invalid room operation.
+   case invalidRoomOperationError = 40002
Tests/AblyChatTests/DefaultRoomsTests.swift (1)

146-152: Consider adding test cases for error message validation.

While the test verifies the error code change from inconsistentRoomOptions to nonspecificUserError, it would be beneficial to also validate the error message content to ensure it provides clear guidance to users.

        await #expect {
            try await rooms.get(roomID: roomID, options: differentOptions)
        } throws: { error in
            isChatError(error, withCodeAndStatusCode: .fixedStatusCode(.nonspecificUserError))
+           guard let artError = error as? ARTErrorInfo else { return false }
+           return artError.message.contains("different set of room options")
        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 76984aa and 6dbb93d.

📒 Files selected for processing (2)
  • Sources/AblyChat/Errors.swift (5 hunks)
  • Tests/AblyChatTests/DefaultRoomsTests.swift (2 hunks)
🔇 Additional comments (2)
Sources/AblyChat/Errors.swift (1)

176-176: Verify error mapping consistency.

The change from inconsistentRoomOptions to nonspecificUserError in the error mapping needs verification to ensure all error paths are properly updated.

✅ Verification successful

Error mapping is consistent and properly updated

The verification shows that:

  • The change from inconsistentRoomOptions to nonspecificUserError in error mapping is consistent
  • All test cases expecting nonspecificUserError are aligned with this mapping
  • The error code mapping in Errors.swift correctly maps inconsistentRoomOptions case to .fixedStatusCode(.nonspecificUserError)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to inconsistentRoomOptions
# and verify all nonspecificUserError mappings

# Search for any remaining references to inconsistentRoomOptions
echo "Checking for remaining references to inconsistentRoomOptions..."
rg "inconsistentRoomOptions" --type swift

# Search for all mappings to nonspecificUserError
echo "Checking all mappings to nonspecificUserError..."
rg "nonspecificUserError" --type swift -A 2 -B 2

Length of output: 4515

Tests/AblyChatTests/DefaultRoomsTests.swift (1)

186-192: LGTM: Test cases properly updated for new error code.

The test cases have been correctly updated to expect the new nonspecificUserError code, maintaining consistency with the changes in Errors.swift.

I should have done this in e7612c9.

The 40000 error code does not have a name in the spec or in the JS Chat
SDK, so I took `badRequest` from errors.json [1].

[1] https://github.com/ably/ably-common/blob/main/protocol/errors.json
@lawrence-forooghian lawrence-forooghian force-pushed the fix-inconsistentRoomOptions-error branch from 6dbb93d to 1756aa3 Compare December 10, 2024 11:41
@lawrence-forooghian lawrence-forooghian merged commit 1b22bb3 into main Dec 10, 2024
12 checks passed
@lawrence-forooghian lawrence-forooghian deleted the fix-inconsistentRoomOptions-error branch December 10, 2024 11:46
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.

2 participants