Skip to content

feat(client): pass isSuccess to ClientRetryPlugin onRetry returned callback#389

Merged
dinwwwh merged 2 commits into
mainfrom
feat/client/improve-retry-plugin-onRetry-callback
Apr 11, 2025
Merged

feat(client): pass isSuccess to ClientRetryPlugin onRetry returned callback#389
dinwwwh merged 2 commits into
mainfrom
feat/client/improve-retry-plugin-onRetry-callback

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Apr 11, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced retry functionality now executes a callback after each retry attempt, clearly indicating success or failure. This improvement provides more robust handling during repeated operations.
  • Documentation

    • Updated documentation to reflect the new retry behavior and callback structure.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 8:13am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 11, 2025

Walkthrough

This pull request updates the onRetry function for the client retry mechanism. The change modifies the callback signature so that it now returns a function accepting a boolean parameter, indicating the success of the retry attempt. Documentation, implementation, and corresponding tests have been updated accordingly: variable names have been adjusted, error handling refined, and tests now simulate multiple retry attempts with eventual success.

Changes

File(s) Change Summary
apps/.../client-retry.md Updated documentation to reflect the new onRetry signature that now returns a function accepting an isSuccess parameter, enabling post-retry logic execution.
packages/client/src/plugins/retry.ts and packages/client/src/plugins/retry.test.ts Modified the onRetry callback: In the implementation, updated the function signature and variable names (e.g., renaming unsubscribe to callback, using currentError), and in tests, implemented a counter-based retry mechanism that succeeds after several attempts with enhanced assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RetryPlugin
    participant OnRetryFn

    Client->>RetryPlugin: Initiate operation with retry logic
    RetryPlugin->>OnRetryFn: Call onRetry(options)
    Note right of OnRetryFn: Returns a callback function
    loop For each retry attempt
        RetryPlugin->>RetryPlugin: Execute retry attempt
        alt Retry fails
            OnRetryFn-->>RetryPlugin: Invoke callback(false)
        else Retry succeeds
            OnRetryFn-->>RetryPlugin: Invoke callback(true)
        end
    end
    RetryPlugin->>Client: Return final result
Loading

Possibly related PRs

  • unnoq/orpc#291: Adjustments to the ClientRetryPlugin class and context handling related to the modified onRetry callback.
  • unnoq/orpc#265: Updates in the test suite for onRetry behavior align with the changes in this pull request.

Poem

I'm a rabbit in code, with hops so bright,
Tweaking retries through day and night.
With a callback that now knows success or failure true,
I dance with logic, fresh and new.
Cheers to clean code—happy hops to you!
🐰✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 11, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@389

@orpc/client

npm i https://pkg.pr.new/@orpc/client@389

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@389

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@389

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@389

@orpc/react

npm i https://pkg.pr.new/@orpc/react@389

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@389

@orpc/server

npm i https://pkg.pr.new/@orpc/server@389

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@389

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@389

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@389

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@389

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@389

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@389

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@389

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@389

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@389

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@389

commit: 3141a7b

Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
packages/client/src/plugins/retry.ts (2)

39-39: Consider using undefined instead of void in union type.

The type signature uses void in a union type, which static analysis tools flag as potentially confusing.

-  onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void)
+  onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => undefined | ((isSuccess: boolean) => void)
🧰 Tools
🪛 Biome (1.9.4)

[error] 39-39: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


80-80: Consider using undefined instead of void in union type.

Similar to the interface declaration, using void in a union type here may cause confusion.

-  let callback: void | ((isSuccess: boolean) => void)
+  let callback: undefined | ((isSuccess: boolean) => void)
🧰 Tools
🪛 Biome (1.9.4)

[error] 80-80: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec326d and 3141a7b.

📒 Files selected for processing (3)
  • apps/content/docs/plugins/client-retry.md (1 hunks)
  • packages/client/src/plugins/retry.test.ts (2 hunks)
  • packages/client/src/plugins/retry.ts (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/client/src/plugins/retry.ts

[error] 39-39: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 80-80: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (8)
apps/content/docs/plugins/client-retry.md (1)

57-63: LGTM: Clear and accurate documentation update.

The documentation has been updated to reflect the new onRetry callback pattern, which now returns a function that accepts an isSuccess parameter. This clearly shows users how to implement logic that executes after a retry attempt completes.

packages/client/src/plugins/retry.test.ts (3)

125-134: LGTM: Good test implementation approach.

This change improves the test by simulating multiple retry attempts with eventual success on the 4th attempt, which better tests the real-world behavior of the retry mechanism.


139-139: Correctly updated expectation to match new behavior.

The test expectation has been properly updated to expect a successful resolution with the "success" value instead of a rejection, aligning with the modified handler implementation.


176-178: LGTM: Properly testing callback arguments.

The test now correctly verifies that the clean callback receives the appropriate boolean values indicating the success status of each retry attempt:

  • false for the first two attempts (failed retries)
  • true for the third attempt (successful retry)
packages/client/src/plugins/retry.ts (4)

83-85: LGTM: Good variable renaming for clarity.

Renaming from current to currentError and adjusting the function signature improves code readability by better reflecting the variable's purpose.


89-92: LGTM: Consistent error handling.

Error handling has been correctly updated to use currentError consistently throughout the code.


110-110: Renamed variable improves semantic clarity.

The variable rename from unsubscribe to callback better reflects its purpose since it's now being used to inform about retry success status.


131-132: LGTM: Properly implements the isSuccess callback.

This implementation correctly:

  1. Passes the success status (!currentError) to the callback
  2. Clears the callback after use to prevent duplicate calls

This aligns with the interface change and documentation.

@dinwwwh dinwwwh merged commit b3c3ac6 into main Apr 11, 2025
8 checks passed
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.

1 participant