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

chore(e2e): improve balance error messages #3375

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Jan 17, 2025

Add context to get balance error messages to make debugging easier. See https://github.com/zeta-chain/infrastructure/issues/1958 as an example of why the current error messages are not sufficient.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling for account balance retrieval operations
    • Improved error messages to provide more context during balance checks

@gartnera gartnera added the no-changelog Skip changelog CI check label Jan 17, 2025
@gartnera gartnera requested a review from a team as a code owner January 17, 2025 17:17
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

The pull request focuses on enhancing error handling in the GetAccountBalances method within the e2e/runner/balances.go file. The modifications systematically improve error reporting by wrapping existing errors with more descriptive context. Each error return now includes a specific message indicating the precise balance retrieval operation that failed, such as "get zeta balance" or similar context-specific descriptions.

Changes

File Change Summary
e2e/runner/balances.go Enhanced error handling for balance retrieval methods by adding contextual error wrapping for multiple blockchain asset types (Zeta, WZETA, ETH ZRC20, ERC20 ZRC20, BTC ZRC20, SOL ZRC20)

Possibly related PRs

Suggested reviewers

  • swift1337
  • skosito
  • kingpinXD
  • ws4charlie
  • brewmaster012
  • lumtis
  • fbac

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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

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.

@gartnera gartnera enabled auto-merge January 17, 2025 17:17
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.39%. Comparing base (7eea20e) to head (04bb582).
Report is 6 commits behind head on develop.

❗ There is a different number of reports uploaded between BASE (7eea20e) and HEAD (04bb582). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (7eea20e) HEAD (04bb582)
2 1
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #3375       +/-   ##
============================================
- Coverage    62.43%   49.39%   -13.04%     
============================================
  Files          449      482       +33     
  Lines        31706    40254     +8548     
============================================
+ Hits         19795    19885       +90     
- Misses       11024    19482     +8458     
  Partials       887      887               

see 50 files with indirect coverage changes

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

🔭 Outside diff range comments (2)
e2e/runner/balances.go (2)

Line range hint 151-157: Align Bitcoin balance error handling with the new pattern

The error handling in Bitcoin-related functions is inconsistent with the improved error messages pattern used elsewhere.

Apply this improvement:

  func (r *E2ERunner) GetBitcoinBalance() (string, error) {
      address, _ := r.GetBtcAddress()
      total, err := r.GetBitcoinBalanceByAddress(address)
      if err != nil {
-         return "", err
+         return "", fmt.Errorf("get bitcoin balance: %w", err)
      }
      return total.String(), nil
  }

  func (r *E2ERunner) GetBitcoinBalanceByAddress(address btcutil.Address) (btcutil.Amount, error) {
      unspentList, err := r.BtcRPCClient.ListUnspentMinMaxAddresses(1, 9999999, []btcutil.Address{address})
      if err != nil {
-         return 0, errors.Wrap(err, "failed to list unspent")
+         return 0, fmt.Errorf("list unspent bitcoin transactions: %w", err)
      }

Also applies to: 164-167


Line range hint 128-130: Improve SPL balance parsing error handling

The SPL balance parsing error could be more descriptive and consistent with the new error pattern.

Apply this improvement:

  solSPLParsed, ok := new(big.Int).SetString(splBalance.Value.Amount, 10)
  if !ok {
-     return AccountBalances{}, errors.New("can't parse spl balance")
+     return AccountBalances{}, fmt.Errorf("parse spl balance %q: invalid format", splBalance.Value.Amount)
  }
🧹 Nitpick comments (2)
e2e/runner/balances.go (2)

53-73: Consider enhancing error handling structure

The error wrapping provides good context but could be improved for better error handling and reduced duplication.

Consider this refactoring approach:

+ type BalanceError struct {
+     TokenType string
+     Err       error
+ }
+
+ func (e *BalanceError) Error() string {
+     return fmt.Sprintf("get %s balance: %v", e.TokenType, e.Err)
+ }
+
+ func (e *BalanceError) Unwrap() error {
+     return e.Err
+ }

  // In GetAccountBalances:
- return AccountBalances{}, fmt.Errorf("get zeta balance: %w", err)
+ return AccountBalances{}, &BalanceError{TokenType: "zeta", Err: err}

This approach:

  1. Provides structured errors that can be type-asserted upstream
  2. Maintains consistent error messaging
  3. Reduces code duplication
  4. Enables better error handling patterns

Line range hint 53-124: Overall error handling improvements look good

The enhanced error messages provide better context for debugging balance-related issues. The consistent use of fmt.Errorf with the %w verb maintains error wrapping capabilities, allowing proper error inspection upstream.

Consider these additional improvements for the future:

  1. Document common error types and their handling in the package documentation
  2. Add error codes or error types for programmatic error handling
  3. Consider implementing error grouping for batch operations
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8166e38 and 04bb582.

📒 Files selected for processing (1)
  • e2e/runner/balances.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
e2e/runner/balances.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-e2e-test / e2e

@gartnera gartnera added this pull request to the merge queue Jan 17, 2025
Merged via the queue into develop with commit 4bdfc0b Jan 17, 2025
42 of 43 checks passed
@gartnera gartnera deleted the zetae2e-balances-error-context branch January 17, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants