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

Improve error handling #366

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Improve error handling #366

merged 5 commits into from
Jul 19, 2024

Conversation

devbugging
Copy link
Contributor

@devbugging devbugging commented Jul 18, 2024

Closes: #70

Description

TBD


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error messages to provide more context for decoding failures in transactions and blocks.
    • Streamlined error handling for transaction submissions, reducing redundancy and improving clarity.
    • Updated error message for out-of-range scenarios to enhance clarity.

@devbugging devbugging self-assigned this Jul 18, 2024
Copy link
Contributor

coderabbitai bot commented Jul 18, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The recent changes focus on improving error handling across multiple functions in the codebase. Enhancements include more informative error messages that provide context for failures, making it easier for developers to diagnose issues. Key functions have been updated to ensure that errors are wrapped with relevant details, promoting better maintainability and debugging capabilities.

Changes

Files Change Summary
api/api.go, models/block.go, models/transaction.go Streamlined error handling and enhanced error messages with additional context in various functions.
services/requester/cross-spork_client.go, services/requester/requester.go Refined error messages for clarity, including specific conditions that lead to errors.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Requester as Requester Service
    participant e.client as External Client

    Client->>Requester: Call executeScriptAtHeight
    Requester->>e.client: ExecuteScriptAtBlockHeight
    e.client-->>Requester: Return result or error
    alt Error contains specific message
        Requester-->>Client: Return ErrOutOfRange
    else Other errors
        Requester-->>Client: Return original error
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Improve error wrapping (#70)

Poem

In the code's embrace, where errors do play,
Clarity blossoms, brightening the way.
Each message refined, as if by a spell,
Debugging's now easier, all will be well.
With code that's more clear, we hop with delight,
A rabbit's joy shines in the code, oh so bright! 🐇✨


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 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
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 e648106 and 1d63611.

Files selected for processing (1)
  • services/requester/requester.go (1 hunks)
Additional comments not posted (2)
services/requester/requester.go (2)

680-680: LGTM!

The addition of error handling logic improves the clarity and specificity of error messages.


686-692: Ensure ErrOutOfRange is handled correctly.

The new error handling logic introduces ErrOutOfRange. Ensure that this error is handled correctly in the upstream code.

Verification successful

ErrOutOfRange is handled correctly.

The error ErrOutOfRange introduced in the new error handling logic is appropriately checked and handled in the codebase. The handling includes proper logging, returning the error when necessary, and adequate test coverage.

  • services/requester/requester.go: Error is logged if not ErrOutOfRange.
  • services/requester/cross-spork_client.go: Error is returned when the client is nil.
  • services/requester/cross-spork_client_test.go: Test cases verify scenarios involving ErrOutOfRange.
  • api/api.go: Error is handled and a formatted error message is returned.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and handling of `ErrOutOfRange` in the codebase.

# Test: Search for the usage and handling of `ErrOutOfRange`. Expect: Proper handling of the error.
rg --type go 'ErrOutOfRange'

Length of output: 1056


Script:

#!/bin/bash
# Extract lines around the usage of ErrOutOfRange in requester.go
rg --type go -A 5 -B 5 'ErrOutOfRange' services/requester/requester.go

# Extract lines around the usage of ErrOutOfRange in cross-spork_client.go
rg --type go -A 5 -B 5 'ErrOutOfRange' services/requester/cross-spork_client.go

# Extract lines around the usage of ErrOutOfRange in cross-spork_client_test.go
rg --type go -A 5 -B 5 'ErrOutOfRange' services/requester/cross-spork_client_test.go

# Extract lines around the usage of ErrOutOfRange in api.go
rg --type go -A 5 -B 5 'ErrOutOfRange' api/api.go

Length of output: 3800

@@ -246,15 +246,15 @@ func decodeTransactionEvent(
if txEvent.TransactionType == types.DirectCallTxType {
directCall, err := types.DirectCallFromEncoded(encodedTx)
if err != nil {
return nil, nil, fmt.Errorf("failed to RLP-decode direct call: %w", err)
return nil, nil, fmt.Errorf("failed to RLP-decode direct call [%x]: %w", encodedTx, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It occurred to me that we have the same exact error message in decodeTransactionEvent & UnmarshalTransaction:

In decodeTransactionEvent:

directCall, err := types.DirectCallFromEncoded(encodedTx)
if err != nil {
	return nil, nil, fmt.Errorf("failed to RLP-decode direct call [%x]: %w", encodedTx, err)
}

gethTx := &gethTypes.Transaction{}
if err := gethTx.UnmarshalBinary(encodedTx); err != nil {
	return nil, nil, fmt.Errorf("failed to RLP-decode transaction [%x]: %w", encodedTx, err)
}

In UnmarshalTransaction:

directCall, err := types.DirectCallFromEncoded(value)
if err != nil {
	return nil, fmt.Errorf("failed to RLP-decode direct call [%x]: %w", value, err)
}

if err := tx.UnmarshalBinary(value); err == nil {
	return TransactionCall{Transaction: tx}, nil
}

return nil, fmt.Errorf("failed to RLP-decode transaction [%x]: %w", value, err)

Can we add a prefix to the error message, so we can know whether the decoding error comes the ingestion component, or from the DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need because the error in the API gets wrapped.

devbugging and others added 2 commits July 19, 2024 13:17
@devbugging devbugging requested a review from m-Peter July 19, 2024 11:17
Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@devbugging devbugging merged commit d37bd82 into main Jul 19, 2024
2 checks passed
@m-Peter m-Peter deleted the gregor/error-handling branch July 19, 2024 11:50
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Improve error wrapping
2 participants