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

introduce MarkTemporary #28

Merged
merged 5 commits into from
Jun 20, 2024
Merged

introduce MarkTemporary #28

merged 5 commits into from
Jun 20, 2024

Conversation

shogo82148
Copy link
Owner

@shogo82148 shogo82148 commented Jun 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced handling for temporary and permanent errors in retry logic.
    • Added functionality to mark errors as temporary or permanent.
  • Tests

    • Added tests for marking errors as permanent or temporary in error-handling logic.

These updates improve error handling by distinguishing between temporary and permanent errors, enhancing the reliability of retry mechanisms.

Copy link
Contributor

coderabbitai bot commented Jun 18, 2024

Walkthrough

The changes introduce enhanced error handling in the retry logic by adding types and methods to mark errors as temporary or permanent. This update includes modifications to the existing DoValue function and the addition of test cases to ensure the proper functioning of the new error handling mechanisms.

Changes

Files Change Summaries
retry.go Added new error types temporaryError and myError, and methods to handle temporary errors in retry logic.
func.go Updated DoValue function error handling to check for the myError type and its temporary field.
func_test.go, retry_test.go Added test functions to validate marking errors as permanent or temporary during DoValue and Do method execution.

Sequence Diagrams

Enhanced Error Handling in DoValue Function

sequenceDiagram
    participant User
    participant DoValue
    participant Policy
    participant CustomError

    User->>DoValue: Call DoValue(ctx, policy, f)
    DoValue->>+Policy: Execute policy logic
    Policy-->>DoValue: Return error (if any)
    DoValue->>DoValue: Check if error is of type `myError`
    alt Error is `myError`
        DoValue->>CustomError: Check temporary flag in error
        alt Temporary flag is true
            DoValue-->>User: Retry based on policy
        else Permanent flag is true
            DoValue-->>User: Return error without retry
        end
    else Error is not `myError`
        DoValue-->>User: Return error
    end
Loading

New Error Types and Methods

sequenceDiagram
    participant Developer
    participant CodeBase
    participant ErrorHandling

    Developer->>CodeBase: Define `temporaryError` and `myError` structs
    CodeBase->>ErrorHandling: Add methods Temporary() and Unwrap()
    Developer->>CodeBase: Implement MarkTemporary function
    ErrorHandling-->>Developer: Enhanced retry logic with temporary error handling
Loading

Poem

A bunny hopped, so full of cheer,
With code to catch the errors near,
Some errors rest, while others try,
To pause a while, then flutter by.

With careful checks, and methods bright,
Our code now handles wrongs just right.
🐇✨


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.

@coveralls
Copy link

Coverage Status

coverage: 90.85% (-1.3%) from 92.199%
when pulling 0163529 on introduce-mark-temporary
into edc7d35 on main.

Copy link
Contributor

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between edc7d35 and 0163529.

Files selected for processing (2)
  • retry.go (2 hunks)
  • retry_test.go (1 hunks)
Additional comments not posted (1)
retry_test.go (1)

283-296: The test for MarkTemporary is well-implemented to ensure that a temporary error allows the maximum number of retries. It's important to ensure these tests cover all potential edge cases, such as the behavior when the maximum retry count is reached.

retry.go Outdated Show resolved Hide resolved
retry.go Outdated Show resolved Hide resolved
retry_test.go Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0163529 and a9c39c4.

Files selected for processing (1)
  • retry.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • retry.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@coveralls
Copy link

Coverage Status

coverage: 90.909% (-1.3%) from 92.199%
when pulling a9c39c4 on introduce-mark-temporary
into edc7d35 on main.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@coveralls
Copy link

Coverage Status

coverage: 90.909% (-1.3%) from 92.199%
when pulling 0618fb5 on introduce-mark-temporary
into edc7d35 on main.

@coveralls
Copy link

Coverage Status

coverage: 90.909% (-1.3%) from 92.199%
when pulling dcd4f97 on introduce-mark-temporary
into edc7d35 on main.

@coveralls
Copy link

Coverage Status

coverage: 92.857% (+0.7%) from 92.199%
when pulling 566c8a5 on introduce-mark-temporary
into edc7d35 on main.

Copy link
Contributor

@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 a9c39c4 and 566c8a5.

Files selected for processing (4)
  • func.go (2 hunks)
  • func_test.go (1 hunks)
  • retry.go (2 hunks)
  • retry_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • retry_test.go
Additional comments not posted (5)
func.go (1)

Line range hint 1-25: The rest of the DoValue function appears well-structured and correct.

Also applies to: 31-46

func_test.go (2)

33-45: The test TestDoValue_MarkPermanent correctly checks for non-retry on permanent errors.


47-60: The test TestDoValue_MarkTemporary correctly verifies the retry logic for temporary errors.

retry.go (2)

107-131: The implementation of the myError type and its methods are correctly defined and follow best practices for custom error types in Go.


126-133: The implementations of MarkTemporary and MarkPermanent are correct and well-documented.

Comment on lines +26 to +30
// short cut for calling Unwrap
if err, ok := err.(*myError); ok {
if err.temporary {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactoring the error handling logic for myError to avoid duplication and improve maintainability.

+ func handleMyError(err error) (bool, error) {
+    if err, ok := err.(*myError); ok {
+        if err.temporary {
+            return true, nil
+        }
+        return false, err.error
+    }
+    return false, nil
+ }
+
+ // Usage in the code
+ shouldContinue, unwrappedErr := handleMyError(err)
+ if shouldContinue {
+     continue
+ }
+ if unwrappedErr != nil {
+     return zero, unwrappedErr
+ }

Also applies to: 47-50

Comment on lines +73 to +77
// short cut for calling Unwrap
if err, ok := err.(*myError); ok {
if err.temporary {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refactoring the error handling logic for myError in the Do function to avoid duplication and improve maintainability, similar to the suggestion made in func.go.

Also applies to: 94-97

@shogo82148 shogo82148 merged commit 488a75f into main Jun 20, 2024
14 checks passed
@shogo82148 shogo82148 deleted the introduce-mark-temporary branch June 20, 2024 02:40
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