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

Handle ErrClientNotActivated and ErrClientNotFound #865

Merged
merged 8 commits into from
Jul 10, 2024
Merged

Conversation

hackerwins
Copy link
Member

@hackerwins hackerwins commented Jul 9, 2024

What this PR does / why we need it?

Handle ErrClientNotActivated and ErrClientNotFound

This commit addresses detailed logic errors returned in RPC Error
response from the server, specifically ErrClientNotActivated and
ErrClientNotFound. It checks for these errors in the RPC response
and handles them by changing the Client's state.

In case of ErrClientNotActivated and ErrClientNotFound, Client's
state is changed to 'Deactivated,' and attached Documents are
changed to Detached. Therefore, if the application is subscribing
the status event using Document.Subscribe, it will receive Detached.

Any background context you want to provide?

What are the relevant tickets?

Addresses yorkie-team/yorkie#928
Related to yorkie-team/yorkie#927

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced custom matchers for error code validation within the vitest testing framework.
  • Bug Fixes

    • Updated error handling to ensure consistent and descriptive error codes across various components.
  • Chores

    • Added test/vitest.d.ts to the .eslintignore file.
    • Bumped versions of multiple packages for improved performance and compatibility.
  • Refactor

    • Improved error handling and updated error codes for better clarity and consistency.

Copy link

coderabbitai bot commented Jul 9, 2024

Walkthrough

This update primarily focuses on enhancing error handling and updating package versions. It involves refactoring error codes for consistency, improving the functionality of error-related modules, and incorporating custom matchers for ViTest to validate error codes. Package versions have been updated to ensure up-to-date dependencies, and some minor tweaks have been made to the .eslintignore file and configuration files.

Changes

File(s) Change Summary
.eslintignore Added test/vitest.d.ts to be ignored for linting.
package.json Bumped versions of several @connectrpc related packages.
src/api/converter.ts Imported new error modules, updated error codes, added errorCodeOf function.
src/client/client.ts Improved error handling, refactored methods, and updated error handling techniques.
src/document/crdt/counter.ts Replaced Code.Unimplemented with Code.ErrUnimplemented for error consistency.
src/document/crdt/primitive.ts Updated error code references in switch-case statements.
src/document/document.ts Improved exception handling with more descriptive error codes.
src/document/json/object.ts Updated error code references to Code.ErrInvalidObjectKey.
src/util/error.ts Updated error naming conventions by prefixing values with "Err".
test/integration/client_test.ts Reworked error code references and added license information.
test/vitest.d.ts Introduced custom matchers for error code validation within ViTest.
test/vitest.setup.ts Introduced a custom Jest matcher toThrowErrorCode for validating expected error codes.
vitest.config.ts Added setupFiles configuration to include setup files for ViTest.

Poem

In a forest of code, errors did roam,
Consistency found them and brought them home.
Packages updated, tests with precision,
Bugs fixed with care, a clear vision.
Hoppity hop, the code sings anew,
Errors handled cleanly, thanks to you! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 57.40741% with 23 lines in your changes missing coverage. Please review.

Project coverage is 80.84%. Comparing base (0fb9700) to head (ed0d710).
Report is 1 commits behind head on main.

Files Patch % Lines
src/client/client.ts 54.54% 14 Missing and 1 partial ⚠️
src/api/converter.ts 36.36% 6 Missing and 1 partial ⚠️
src/document/document.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #865      +/-   ##
==========================================
- Coverage   80.91%   80.84%   -0.07%     
==========================================
  Files          60       60              
  Lines        4615     4637      +22     
  Branches      937      942       +5     
==========================================
+ Hits         3734     3749      +15     
- Misses        613      620       +7     
  Partials      268      268              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hackerwins hackerwins changed the title Add errorCodeOf to handle logic errors Handle ErrClientNotActivated Jul 10, 2024
@hackerwins hackerwins changed the title Handle ErrClientNotActivated Handle ErrClientNotActivated and ErrClientNotFound Jul 10, 2024
@hackerwins hackerwins marked this pull request as ready for review July 10, 2024 03:29
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 334a920 and ed0d710.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (13)
  • .eslintignore (1 hunks)
  • package.json (2 hunks)
  • src/api/converter.ts (10 hunks)
  • src/client/client.ts (19 hunks)
  • src/document/crdt/counter.ts (3 hunks)
  • src/document/crdt/primitive.ts (2 hunks)
  • src/document/document.ts (2 hunks)
  • src/document/json/object.ts (2 hunks)
  • src/util/error.ts (1 hunks)
  • test/integration/client_test.ts (6 hunks)
  • test/vitest.d.ts (1 hunks)
  • test/vitest.setup.ts (1 hunks)
  • vitest.config.ts (1 hunks)
Files skipped from review due to trivial changes (3)
  • .eslintignore
  • src/util/error.ts
  • vitest.config.ts
Additional comments not posted (41)
test/vitest.setup.ts (1)

1-33: LGTM! Custom matcher toThrowErrorCode.

The custom matcher toThrowErrorCode is correctly implemented and useful for validating error codes in tests.

test/vitest.d.ts (1)

1-31: LGTM! Type definitions for custom matcher toThrowErrorCode.

The type definitions for the custom matcher toThrowErrorCode are correct and comprehensive.

package.json (2)

43-43: LGTM! Dependency update for @buf/googleapis_googleapis.connectrpc_es.

The version update to ^1.4.0-20240524201209-f0e53af8f2fc.3 is correct.


46-46: LGTM! Dependency update for @connectrpc/protoc-gen-connect-es.

The version update to ^1.4.0 is correct.

src/document/json/object.ts (2)

150-150: LGTM! Improved error handling in setInternal.

The error code update to Code.ErrInvalidObjectKey improves error handling.


186-186: LGTM! Improved error handling in buildObjectMembers.

The error code update to Code.ErrInvalidObjectKey improves error handling.

src/document/crdt/counter.ts (3)

73-75: LGTM! Consistent error handling.

The use of Code.ErrUnimplemented for unimplemented types is consistent with the new error handling approach.


103-105: LGTM! Consistent error handling.

The use of Code.ErrUnimplemented for unimplemented types in valueFromBytes is consistent with the new error handling approach.


232-234: LGTM! Consistent error handling.

The use of Code.ErrUnimplemented for unimplemented types in toBytes is consistent with the new error handling approach.

src/document/crdt/primitive.ts (1)

95-97: LGTM! Consistent error handling.

The use of Code.ErrUnimplemented for unimplemented types in valueFromBytes is consistent with the new error handling approach.

src/client/client.ts (20)

249-251: LGTM! Improved error handling in activate method.

The use of handleConnectError improves error handling consistency.


275-277: LGTM! Improved error handling in deactivate method.

The use of handleConnectError improves error handling consistency.


293-296: LGTM! Improved error handling in attach method.

The use of Code.ErrClientNotActivated and Code.ErrDocumentNotDetached improves error handling consistency.


300-302: LGTM! Improved error handling in attach method.

The use of Code.ErrDocumentNotDetached improves error handling consistency.


365-368: LGTM! Improved error handling in detach method.

The use of Code.ErrClientNotActivated improves error handling consistency.


373-375: LGTM! Improved error handling in detach method.

The use of Code.ErrDocumentNotAttached improves error handling consistency.


417-420: LGTM! Improved error handling in changeSyncMode method.

The use of Code.ErrClientNotActivated improves error handling consistency.


426-428: LGTM! Improved error handling in changeSyncMode method.

The use of Code.ErrDocumentNotAttached improves error handling consistency.


469-472: LGTM! Improved error handling in sync method.

The use of Code.ErrClientNotActivated improves error handling consistency.


479-481: LGTM! Improved error handling in sync method.

The use of Code.ErrDocumentNotAttached improves error handling consistency.


483-489: LGTM! Improved error handling in sync method.

The use of handleConnectError improves error handling consistency.


497-501: LGTM! Improved error handling in sync method.

The use of handleConnectError improves error handling consistency.


510-513: LGTM! Improved error handling in remove method.

The use of Code.ErrClientNotActivated improves error handling consistency.


518-520: LGTM! Improved error handling in remove method.

The use of Code.ErrDocumentNotAttached improves error handling consistency.


546-548: LGTM! Improved error handling in remove method.

The use of handleConnectError improves error handling consistency.


612-614: LGTM! Improved error handling in runSyncLoop method.

The use of handleConnectError improves error handling consistency.


633-635: LGTM! Improved error handling in runWatchLoop method.

The use of Code.ErrDocumentNotAttached improves error handling consistency.


644-647: LGTM! Improved error handling in runWatchLoop method.

The use of Code.ErrClientNotActivated improves error handling consistency.


819-822: LGTM! Improved error handling in handleConnectError method.

The method now correctly handles Code.ErrClientNotActivated and Code.ErrClientNotFound.


731-738: LGTM! Improved client state management in deactivateInternal method.

The method correctly updates the client status to Deactivated and detaches documents.

test/integration/client_test.ts (8)

66-81: LGTM! Comprehensive error handling tests in Can attach/detach document.

The test case correctly checks for Code.ErrDocumentNotDetached and Code.ErrDocumentNotAttached.


Line range hint 820-833: LGTM! Comprehensive retry logic tests in Should retry on network failure and eventually succeed.

The test case correctly checks for ConnectError with different error codes and verifies client state management.


Line range hint 753-780: LGTM! Comprehensive sync logic tests in Should apply previous changes when switching to realtime sync.

The test case correctly checks for applying changes made while in manual sync mode.


Line range hint 781-815: LGTM! Comprehensive sync logic tests in Should not include changes applied in push-only mode when switching to realtime sync.

The test case correctly checks for excluding changes made in push-only mode.


Line range hint 816-848: LGTM! Comprehensive sync logic tests in Should prevent remote changes in push-only mode.

The test case correctly checks for preventing remote changes in push-only mode.


Line range hint 849-881: LGTM! Comprehensive sync logic tests in Should prevent remote changes in sync-off mode.

The test case correctly checks for preventing remote changes in sync-off mode.


Line range hint 882-902: LGTM! Comprehensive sync logic tests in Should avoid unnecessary syncs in push-only mode.

The test case correctly checks for avoiding unnecessary syncs in push-only mode.


798-800: LGTM! Comprehensive request handling tests in Should handle each request one by one.

The test case correctly checks for handling requests sequentially.

src/api/converter.ts (1)

785-785: Consider specifying the return type as Code.

The function returns a string, which might not be the expected type. Ensure the return type matches the expected Code enum.

- export function errorCodeOf(error: ConnectError): string {
+ export function errorCodeOf(error: ConnectError): Code {
src/document/document.ts (2)

630-630: Correctly handle ErrDocumentRemoved error.

The addition of the error handling for ErrDocumentRemoved ensures that the document update operation is prevented when the document is removed. This aligns with the expected behavior.


1592-1595: Correctly handle ErrInvalidArgument error.

The addition of the error handling for ErrInvalidArgument ensures that the getValueByPath method correctly validates the path argument, preventing invalid paths from causing issues.

src/api/converter.ts Show resolved Hide resolved
src/api/converter.ts Show resolved Hide resolved
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