Skip to content

Conversation

@Tofel
Copy link
Contributor

@Tofel Tofel commented Oct 22, 2025

This pull request focuses on improving error messages and making them more actionable throughout the seth package. It replaces the usage of the github.com/pkg/errors library with Go's standard fmt.Errorf, and revises error handling to provide clearer guidance and troubleshooting steps for users. The changes affect configuration validation, contract ABI lookup, block statistics, and client initialization, making it easier for developers to diagnose and resolve common issues.

Error message improvements and actionable guidance:

  • Replaced generic error messages with detailed, user-friendly messages across configuration validation, contract ABI lookup, and block statistics logic in seth.go, abi_finder.go, and block_stats.go. These messages now include troubleshooting steps and links to documentation or issue trackers where relevant. [1] [2] [3] [4] [5] [6]

Error handling and library updates:

  • Removed all usages of github.com/pkg/errors and replaced them with standard fmt.Errorf, simplifying imports and error wrapping throughout the codebase. [1] [2] [3] [4]

Client initialization and configuration validation:

  • Enhanced error messages in client creation functions (NewClientWithConfig, NewClientRaw) to clarify configuration issues, RPC connectivity problems, and contract mapping errors, providing actionable next steps for users. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Documentation:

  • Added a changelog entry summarizing the review and improvement of error messages, highlighting their increased clarity and actionability.

Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.

Why

This patch aims to improve error handling and messaging across the Seth library, particularly focusing on providing more actionable feedback and ensuring compatibility with updated dependencies.

What

  • Error Handling Enhancements: Replaced the usage of github.com/pkg/errors with Go's standard errors package and custom error formatting to provide clearer, more actionable error messages.
  • Dependency Updates: Removed unnecessary dependencies to streamline the package and avoid potential conflicts.
  • Configuration Validation: Added checks and informative messages for configuration-related errors, ensuring users are aware of misconfigurations.
  • Transaction Handling: Improved the clarity of messages related to transaction processing, gas estimation, and nonce management, helping users diagnose and resolve issues more efficiently.
  • Code Refactoring: Minor refactoring for better readability and maintenance, including simplifying error handling patterns and updating function signatures to align with best practices.

Specific Changes Include:

  • Replaced github.com/pkg/errors with standard errors package for error wrapping.
  • Enhanced error messages across the library to include suggestions for resolution.
  • Added validation for configuration settings, with clear errors if invalid values are detected.
  • Improved logging and error reporting during transaction processing, including gas estimation and nonce management.
  • Streamlined dependency usage by removing unnecessary imports.
  • Minor refactoring for improved code clarity and maintainability.

@Tofel Tofel force-pushed the dx-2128-seth-better-error-msgs branch from 0d05ec3 to 90fa726 Compare October 23, 2025 15:31
@Tofel Tofel requested a review from Copilot October 24, 2025 15:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR focuses on improving error messages across the Seth library by replacing the github.com/pkg/errors package with Go's standard error handling (fmt.Errorf and errors package) and enhancing error messages with actionable troubleshooting guidance. The changes systematically improve user experience by providing clearer, more detailed error messages that include potential causes and solutions.

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
seth/go.mod Moved pkg/errors from direct to indirect dependency
seth/.changeset/v1.51.4.md Added changelog entry documenting the error message improvements
seth/.tool-versions Added golangci-lint version specification
seth/util.go Enhanced error messages for insufficient funds with detailed balance information and actionable solutions
seth/tracing.go Improved error messages for tracer initialization, trace retrieval, and call decoding with troubleshooting steps
seth/retry.go Enhanced error messages for transaction retry failures and gas bumping issues
seth/nonce.go Improved nonce manager error messages with configuration guidance
seth/keyfile.go Enhanced error messages for key generation and fund return operations
seth/header_cache.go Improved nil header error message with issue reporting guidance
seth/gas_adjuster.go Enhanced gas estimation error messages with network congestion and RPC troubleshooting
seth/gas.go Improved gas fee estimation error messages with actionable solutions
seth/decode.go Enhanced transaction decoding error messages with detailed failure explanations
seth/contract_store.go Improved ABI/BIN loading error messages with file discovery and generation guidance
seth/config.go Enhanced configuration validation error messages with detailed setup instructions
seth/cmd/seth.go Updated CLI error handling to use standard error wrapping
seth/client.go Comprehensive error message improvements across client initialization, validation, and transaction handling
seth/block_stats.go Enhanced block statistics error messages with RPC connectivity troubleshooting
seth/abi_finder.go Improved ABI lookup error messages with detailed troubleshooting steps
seth/client_builder.go Updated imports to use standard errors package
lib/utils/seth/seth.go Enhanced Seth configuration error messages with setup guidance
Test files (multiple) Updated test assertions to use Contains instead of exact string matching for improved flexibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +712 to +717
gasLeft := mustSafeInt64(dc.GasLimit) - mustSafeInt64(dc.GasUsed)
if gasLeft < 0 {
l.Debug().Str(fmt.Sprintf("%s- Gas left", indentation), fmt.Sprintf("%d (negative due to gas refunds or stipends)", gasLeft)).Send()
} else {
l.Debug().Str(fmt.Sprintf("%s- Gas left", indentation), fmt.Sprintf("%d", gasLeft)).Send()
}
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

Potential panic from mustSafeInt64 if dc.GasLimit or dc.GasUsed exceed math.MaxInt64. The values come from blockchain data which uses uint64, but gas values in practice rarely exceed int64 max. Consider adding validation or handling overflow gracefully instead of panicking, especially since this is just for logging.

Copilot uses AI. Check for mistakes.
if diff == 0 {
return []*DecodedCall{}
}

Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

This early return when diff == 0 causes the function to skip creating and returning the missedCalls slice that would be populated below. However, the logic at line 547-624 still constructs missedCalls even when not needed. Consider moving this check earlier in the function or restructuring the logic to avoid unnecessary computation when there are no missing calls.

Suggested change
// Only construct missedCalls if there are missing calls

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is absolutely crazy... since there are no missed calls (diff == 0), then early exist happens when it should. And if there are missed calls then constructing them is always needed 🤯

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