-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: prep for errors v2 #20539
feat: prep for errors v2 #20539
Conversation
Important Review skippedReview was skipped as selected files did not have any reviewable changes. Files selected but had no reviewable changes (1)
You can disable this status message by setting the WalkthroughThe recent updates in the errors package involve significant refactoring to enhance error handling and testing. Key changes include removing custom error interfaces, adopting Go's standard Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ErrorsPackage
participant CustomError
Client->>ErrorsPackage: Call abciInfo(err)
ErrorsPackage->>ErrorsPackage: Use errors.As to check for CustomError
ErrorsPackage->>CustomError: Extract code and codespace
CustomError-->>ErrorsPackage: Return code and codespace
ErrorsPackage-->>Client: Return error info (code, codespace)
sequenceDiagram
participant Test
participant ErrorsPackage
Test->>ErrorsPackage: Call ABCIInfo(err, debug)
ErrorsPackage->>ErrorsPackage: Wrap error with fmt.Errorf
ErrorsPackage-->>Test: Return formatted error
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
marking as r4r, but still need to add docs |
There was a problem hiding this 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
Outside diff range and nitpick comments (3)
errors/errors_test.go (1)
Line range hint
19-44
: TheRegister
function is undefined in this context. Ensure it is imported or defined within the package.+ import "path/to/package/where/Register/is/defined"
Tools
golangci-lint
8-8: undefined: ABCIError (typecheck)
11-11: undefined: ABCIError (typecheck)
errors/abci.go (1)
Line range hint
17-17
: UndefinedUndefinedCodespace
. Ensure it is defined or imported correctly.+ const UndefinedCodespace = "your_defined_codespace"
errors/abci_test.go (1)
Line range hint
18-29
: UndefinedErrUnauthorized
andtestCodespace
. Ensure they are defined or imported correctly.+ var ErrUnauthorized = errors.New("unauthorized") + const testCodespace = "your_defined_codespace"Tools
golangci-lint
22-22: undefined: testCodespace (typecheck)
25-25: undefined: ErrUnauthorized (typecheck)
28-28: undefined: ErrUnauthorized (typecheck)
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (2)
errors/go.mod
is excluded by!**/*.mod
errors/go.sum
is excluded by!**/*.sum
Files selected for processing (4)
- errors/abci.go (5 hunks)
- errors/abci_test.go (4 hunks)
- errors/errors.go (3 hunks)
- errors/errors_test.go (1 hunks)
Additional context used
Path-based instructions (4)
errors/errors_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"errors/abci.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.errors/abci_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"errors/errors.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
golangci-lint
errors/errors_test.go
19-19: undefined: Register (typecheck)
20-20: undefined: Register (typecheck)
21-21: undefined: Register (typecheck)
22-22: undefined: Register (typecheck)
23-23: undefined: Register (typecheck)
24-24: undefined: Register (typecheck)
25-25: undefined: Register (typecheck)
26-26: undefined: Register (typecheck)
27-27: undefined: Register (typecheck)
28-28: undefined: Register (typecheck)
29-29: undefined: Register (typecheck)
30-30: undefined: Register (typecheck)
31-31: undefined: Register (typecheck)
32-32: undefined: Register (typecheck)
33-33: undefined: Register (typecheck)
34-34: undefined: Register (typecheck)
35-35: undefined: Register (typecheck)
36-36: undefined: Register (typecheck)
37-37: undefined: Register (typecheck)
38-38: undefined: Register (typecheck)
39-39: undefined: Register (typecheck)
40-40: undefined: Register (typecheck)
41-41: undefined: Register (typecheck)
42-42: undefined: Register (typecheck)
43-43: undefined: Register (typecheck)
44-44: undefined: Register (typecheck)
8-8: undefined: ABCIError (typecheck)
11-11: undefined: ABCIError (typecheck)
errors/abci.go
17-17: undefined: UndefinedCodespace (typecheck)
59-59: undefined: Error (typecheck)
77-77: undefined: Error (typecheck)
errors/abci_test.go
18-18: undefined: ErrUnauthorized (typecheck)
21-21: undefined: ErrUnauthorized (typecheck)
22-22: undefined: testCodespace (typecheck)
25-25: undefined: ErrUnauthorized (typecheck)
28-28: undefined: ErrUnauthorized (typecheck)
29-29: undefined: testCodespace (typecheck)
39-39: undefined: Error (typecheck)
50-50: undefined: UndefinedCodespace (typecheck)
56-56: undefined: ABCIInfo (typecheck)
71-71: undefined: ErrUnauthorized (typecheck)
72-72: undefined: ABCIInfo (typecheck)
81-81: undefined: ErrTxDecode (typecheck)
82-82: undefined: ErrInvalidAddress (typecheck)
83-83: undefined: ErrPanic (typecheck)
114-114: undefined: ABCIInfo (typecheck)
Additional comments not posted (2)
errors/errors_test.go (1)
7-12
: EnsureABCIError
is defined and accessible in the test context.Verification successful
The
ABCIError
function is defined and accessible in the test context. Now, let's verify if the error messages generated byABCIError
match the expected output in the test cases.
The previous attempt to verify the error messages generated by
ABCIError
failed because thego
command was not found in the environment. Instead, let's analyze theABCIError
function and its dependencies to ensure the error messages match the expected output.
The
ABCIError
function, along with its dependencies (getUsed
function andError
struct), has been verified. ThegetUsed
function returns a specific error message fortestCodespace
and code2
, which is "tx parse error". For other cases,ABCIError
returns a default "unknown" error message.The test cases in
errors/errors_test.go
are correctly checking for these expected error messages.
- For
ABCIError(testCodespace, 2, "custom")
, the expected error message is "custom: tx parse error".- For
ABCIError("unknown", 1, "custom")
, the expected error message is "custom: unknown".These expectations align with the implementation of the
ABCIError
function.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the definition and accessibility of `ABCIError` in the test context. # Test: Search for the definition of `ABCIError`. Expect: Definition found. ast-grep --lang go --pattern $'func ABCIError($_, $_, $_) $_ { $$$ }'Length of output: 587
Script:
#!/bin/bash # Description: Verify the error messages generated by `ABCIError` for the given inputs. # Test: Check the error message for `ABCIError(testCodespace, 2, "custom")`. # Expect: "custom: tx parse error" echo 'package main import ( "fmt" ) type Error struct { codespace string code uint32 desc string } func getUsed(codespace string, code uint32) error { if codespace == "testCodespace" && code == 2 { return fmt.Errorf("tx parse error") } return nil } func ABCIError(codespace string, code uint32, log string) error { if e := getUsed(codespace, code); e != nil { return fmt.Errorf("%s: %w", log, e) } return fmt.Errorf("%s: %w", log, &Error{codespace: codespace, code: code, desc: "unknown"}) } func main() { err := ABCIError("testCodespace", 2, "custom") fmt.Println(err.Error()) err = ABCIError("unknown", 1, "custom") fmt.Println(err.Error()) }' > verify_abcierror.go # Run the Go script to verify the error messages. go run verify_abcierror.goLength of output: 780
Script:
#!/bin/bash # Description: Analyze the `ABCIError` function and its dependencies to verify the error messages. # Search for the `getUsed` function definition. ast-grep --lang go --pattern $'func getUsed($_, $_) $_ { $$$ }' # Search for the `Error` struct definition. ast-grep --lang go --pattern $'type Error struct { $$$ }'Length of output: 977
Tools
golangci-lint
8-8: undefined: ABCIError (typecheck)
11-11: undefined: ABCIError (typecheck)
errors/errors.go (1)
63-67
: Ensure theError
type is defined and thatfmt.Errorf
is used correctly for error wrapping.
space, code, log := ABCIInfo(tc.err, tc.debug) | ||
s.Require().Equal(tc.wantSpace, space, testName) | ||
s.Require().Equal(tc.wantCode, code, testName) | ||
s.Require().Equal(tc.wantLog, log, testName) | ||
}) | ||
} | ||
} | ||
|
||
func (s *abciTestSuite) TestABCIInfoStacktrace() { | ||
cases := map[string]struct { | ||
err error | ||
debug bool | ||
wantStacktrace bool | ||
wantErrMsg string | ||
}{ | ||
"wrapped SDK error in debug mode provides stacktrace": { | ||
err: Wrap(ErrUnauthorized, "wrapped"), | ||
debug: true, | ||
wantStacktrace: true, | ||
wantErrMsg: "wrapped: unauthorized", | ||
}, | ||
"wrapped SDK error in non-debug mode does not have stacktrace": { | ||
err: Wrap(ErrUnauthorized, "wrapped"), | ||
debug: false, | ||
wantStacktrace: false, | ||
wantErrMsg: "wrapped: unauthorized", | ||
}, | ||
"wrapped stdlib error in debug mode provides stacktrace": { | ||
err: Wrap(fmt.Errorf("stdlib"), "wrapped"), | ||
debug: true, | ||
wantStacktrace: true, | ||
wantErrMsg: "wrapped: stdlib", | ||
}, | ||
} | ||
|
||
const thisTestSrc = "cosmossdk.io/errors.(*abciTestSuite).TestABCIInfoStacktrace" | ||
|
||
for testName, tc := range cases { | ||
s.T().Run(testName, func(t *testing.T) { | ||
_, _, log := ABCIInfo(tc.err, tc.debug) | ||
if !tc.wantStacktrace { | ||
s.Require().Equal(tc.wantErrMsg, log, testName) | ||
} else { | ||
s.Require().True(strings.Contains(log, thisTestSrc), testName) | ||
s.Require().True(strings.Contains(log, tc.wantErrMsg), testName) | ||
if space != tc.wantSpace { | ||
t.Errorf("%s: expected space %s, got %s", testName, tc.wantSpace, space) | ||
} | ||
if code != tc.wantCode { | ||
t.Errorf("%s: expected code %d, got %d", testName, tc.wantCode, code) | ||
} | ||
if log != tc.wantLog { | ||
t.Errorf("%s: expected log %s, got %s", testName, tc.wantLog, log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The ABCIInfo
function is not accessible in the test context because the package containing it is not imported in errors/abci_test.go
. Please add the necessary import statement to ensure ABCIInfo
is available for testing.
errors/abci_test.go
does not import the package containingABCIInfo
.
Analysis chain
Ensure ABCIInfo
is defined and accessible in the test context.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the definition and accessibility of `ABCIInfo` in the test context.
# Test: Search for the definition of `ABCIInfo`. Expect: Definition found.
ast-grep --lang go --pattern $'func ABCIInfo($_, $_) ($_,$_,$_){ $$$ }'
Length of output: 581
Script:
#!/bin/bash
# Description: Verify if `errors/abci_test.go` imports the package containing `ABCIInfo`.
# Test: Search for import statements in `errors/abci_test.go`. Expect: Import statement for `errors/abci.go` found.
rg --lang go --pattern 'import' errors/abci_test.go
Length of output: 460
Script:
#!/bin/bash
# Description: Verify if `errors/abci_test.go` imports the package containing `ABCIInfo`.
# Test: Search for import statements in `errors/abci_test.go`. Expect: Import statement for `errors/abci.go` found.
rg 'import' errors/abci_test.go
Length of output: 40
Script:
#!/bin/bash
# Description: List all import statements in `errors/abci_test.go` to verify if the package containing `ABCIInfo` is imported.
# Test: List all import statements in `errors/abci_test.go`. Expect: Import statement for `errors/abci.go` or its package found.
rg '^import' -A 10 errors/abci_test.go
Length of output: 193
Tools
golangci-lint
56-56: undefined: ABCIInfo (typecheck)
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (2)
- errors/abci.go (4 hunks)
- errors/abci_test.go (4 hunks)
Additional context used
Path-based instructions (2)
errors/abci.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.errors/abci_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
golangci-lint
errors/abci.go
17-17: undefined: UndefinedCodespace (typecheck)
59-59: undefined: Error (typecheck)
77-77: undefined: Error (typecheck)
errors/abci_test.go
18-18: undefined: ErrUnauthorized (typecheck)
21-21: undefined: ErrUnauthorized (typecheck)
22-22: undefined: testCodespace (typecheck)
25-25: undefined: ErrUnauthorized (typecheck)
28-28: undefined: ErrUnauthorized (typecheck)
29-29: undefined: testCodespace (typecheck)
39-39: undefined: Error (typecheck)
50-50: undefined: UndefinedCodespace (typecheck)
56-56: undefined: ABCIInfo (typecheck)
71-71: undefined: ErrUnauthorized (typecheck)
72-72: undefined: ABCIInfo (typecheck)
81-81: undefined: ErrTxDecode (typecheck)
82-82: undefined: ErrInvalidAddress (typecheck)
83-83: undefined: ErrPanic (typecheck)
114-114: undefined: ABCIInfo (typecheck)
Additional comments not posted (2)
errors/abci.go (1)
4-4
: Ensure the newerrors
import is utilized effectively throughout the file.errors/abci_test.go (1)
56-64
: Ensure theABCIInfo
function is accessible and correctly used in the test context. Verify that all test cases are correctly invoking this function and handling its outputs.Also applies to: 70-75, 78-117
Verification successful
The
ABCIInfo
function is defined inerrors/abci.go
and is correctly invoked in the test cases withinerrors/abci_test.go
. The test cases handle its outputs appropriately.
errors/abci_test.go
lines:
space, code, log := ABCIInfo(tc.err, tc.debug)
_, _, log := ABCIInfo(err, false)
_, _, log := ABCIInfo(spec.src, spec.debug)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the definition and accessibility of `ABCIInfo` in the test context. # Test: Search for the definition of `ABCIInfo`. Expect: Definition found. ast-grep --lang go --pattern $'func ABCIInfo($_, $_) ($_,$_,$_){ $$$ }'Length of output: 581
Script:
#!/bin/bash # Description: Verify that `ABCIInfo` is correctly invoked in the test cases within `errors/abci_test.go`. # Test: Search for invocations of `ABCIInfo` in `errors/abci_test.go`. rg 'ABCIInfo' errors/abci_test.goLength of output: 259
Tools
golangci-lint
56-56: undefined: ABCIInfo (typecheck)
errors/abci.go
Outdated
var customErr *Error | ||
if errors.As(err, &customErr) { | ||
return customErr.ABCICode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Error
type is undefined in this context. Ensure it is imported or defined within the package.
+ type Error struct {
+ codespace string
+ code uint32
+ desc string
+ }
Also applies to: 77-79
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
var customErr *Error | |
if errors.As(err, &customErr) { | |
return customErr.ABCICode() | |
var customErr *Error | |
if errors.As(err, &customErr) { | |
return customErr.ABCICode() | |
type Error struct { | |
codespace string | |
code uint32 | |
desc string | |
} |
Tools
golangci-lint
59-59: undefined: Error (typecheck)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 💪
Some minor nits on the code. Bonus points would be available if you can restore some of the public methods in the package to support a better dev UX. errors.Wrap
was quite popular in modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like I am missing some context, don't we need the stacktrace further more?
stack trace can be added manually, but it wont be done automatically in errors/v2. Most of the stacktraces are dropped in client errors anyways |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- errors/abci_test.go (4 hunks)
- errors/errors.go (5 hunks)
Additional context used
Path-based instructions (2)
errors/abci_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"errors/errors.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
golangci-lint
errors/abci_test.go
18-18: undefined: ErrUnauthorized (typecheck)
21-21: undefined: ErrUnauthorized (typecheck)
22-22: undefined: testCodespace (typecheck)
25-25: undefined: ErrUnauthorized (typecheck)
28-28: undefined: ErrUnauthorized (typecheck)
29-29: undefined: testCodespace (typecheck)
39-39: undefined: Error (typecheck)
50-50: undefined: UndefinedCodespace (typecheck)
56-56: undefined: ABCIInfo (typecheck)
73-73: undefined: ErrTxDecode (typecheck)
74-74: undefined: ErrInvalidAddress (typecheck)
75-75: undefined: ErrPanic (typecheck)
106-106: undefined: ABCIInfo (typecheck)
Additional comments not posted (2)
errors/errors.go (2)
63-63
: Ensure proper error wrapping inABCIError
function.This change correctly wraps the error, maintaining the original error context.
114-114
: RefactorWrap
function to handle nil errors gracefully.This implementation correctly returns nil when the error is nil, avoiding unnecessary wrapping.
myErrDecode = fmt.Errorf("test: %w", ErrTxDecode) | ||
myErrAddr = fmt.Errorf("tester: %w", ErrInvalidAddress) | ||
myPanic = ErrPanic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure error constants like ErrTxDecode
, ErrInvalidAddress
, and ErrPanic
are defined or imported.
+ import (
+ "path/to/errors/constants" // Adjust the import path as necessary
+ )
Committable suggestion was skipped due to low confidence.
Tools
golangci-lint
73-73: undefined: ErrTxDecode (typecheck)
74-74: undefined: ErrInvalidAddress (typecheck)
75-75: undefined: ErrPanic (typecheck)
@@ -37,7 +22,7 @@ | |||
wantSpace: testCodespace, | |||
}, | |||
"wrapped SDK error": { | |||
err: Wrap(Wrap(ErrUnauthorized, "foo"), "bar"), | |||
err: fmt.Errorf("bar: %w", fmt.Errorf("foo: %w", ErrUnauthorized)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined error constant ErrUnauthorized
needs to be defined or imported.
+ import (
+ "path/to/errors/constants" // Adjust the import path as necessary
+ )
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
err: fmt.Errorf("bar: %w", fmt.Errorf("foo: %w", ErrUnauthorized)), | |
import ( | |
"path/to/errors/constants" // Adjust the import path as necessary | |
) | |
func TestErrors(t *testing.T) { | |
tests := []struct { | |
name string | |
err error | |
}{ | |
{ | |
name: "unauthorized error", | |
err: fmt.Errorf("bar: %w", fmt.Errorf("foo: %w", ErrUnauthorized)), | |
}, | |
} | |
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
if tt.err == nil { | |
t.Errorf("expected error, got nil") | |
} | |
}) | |
} | |
} |
Tools
golangci-lint
25-25: undefined: ErrUnauthorized (typecheck)
t.Run(testName, func(t *testing.T) { | ||
space, code, log := ABCIInfo(tc.err, tc.debug) | ||
s.Require().Equal(tc.wantSpace, space, testName) | ||
s.Require().Equal(tc.wantCode, code, testName) | ||
s.Require().Equal(tc.wantLog, log, testName) | ||
}) | ||
} | ||
} | ||
|
||
func (s *abciTestSuite) TestABCIInfoStacktrace() { | ||
cases := map[string]struct { | ||
err error | ||
debug bool | ||
wantStacktrace bool | ||
wantErrMsg string | ||
}{ | ||
"wrapped SDK error in debug mode provides stacktrace": { | ||
err: Wrap(ErrUnauthorized, "wrapped"), | ||
debug: true, | ||
wantStacktrace: true, | ||
wantErrMsg: "wrapped: unauthorized", | ||
}, | ||
"wrapped SDK error in non-debug mode does not have stacktrace": { | ||
err: Wrap(ErrUnauthorized, "wrapped"), | ||
debug: false, | ||
wantStacktrace: false, | ||
wantErrMsg: "wrapped: unauthorized", | ||
}, | ||
"wrapped stdlib error in debug mode provides stacktrace": { | ||
err: Wrap(fmt.Errorf("stdlib"), "wrapped"), | ||
debug: true, | ||
wantStacktrace: true, | ||
wantErrMsg: "wrapped: stdlib", | ||
}, | ||
} | ||
|
||
const thisTestSrc = "cosmossdk.io/errors.(*abciTestSuite).TestABCIInfoStacktrace" | ||
|
||
for testName, tc := range cases { | ||
s.T().Run(testName, func(t *testing.T) { | ||
_, _, log := ABCIInfo(tc.err, tc.debug) | ||
if !tc.wantStacktrace { | ||
s.Require().Equal(tc.wantErrMsg, log, testName) | ||
} else { | ||
s.Require().True(strings.Contains(log, thisTestSrc), testName) | ||
s.Require().True(strings.Contains(log, tc.wantErrMsg), testName) | ||
if space != tc.wantSpace { | ||
t.Errorf("%s: expected space %s, got %s", testName, tc.wantSpace, space) | ||
} | ||
if code != tc.wantCode { | ||
t.Errorf("%s: expected code %d, got %d", testName, tc.wantCode, code) | ||
} | ||
if log != tc.wantLog { | ||
t.Errorf("%s: expected log %s, got %s", testName, tc.wantLog, log) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor test cases to use assertions for improved readability and maintainability.
- if space != tc.wantSpace {
- t.Errorf("%s: expected space %s, got %s", testName, tc.wantSpace, space)
- }
- if code != tc.wantCode {
- t.Errorf("%s: expected code %d, got %d", testName, tc.wantCode, code)
- }
- if log != tc.wantLog {
- t.Errorf("%s: expected log %s, got %s", testName, tc.wantLog, log)
- }
+ assert.Equal(t, tc.wantSpace, space, "%s: expected space %s, got %s", testName, tc.wantSpace, space)
+ assert.Equal(t, tc.wantCode, code, "%s: expected code %d, got %d", testName, tc.wantCode, code)
+ assert.Equal(t, tc.wantLog, log, "%s: expected log %s, got %s", testName, tc.wantLog, log)
Committable suggestion was skipped due to low confidence.
Tools
golangci-lint
56-56: undefined: ABCIInfo (typecheck)
} | ||
|
||
func (s *abciTestSuite) TestABCInfo() { | ||
func TestABCInfo(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The search results indicate that there are no direct references to the additional error handling functions (debugErrEncoder
, defaultErrEncoder
, abciCode
, abciCodespace
, errIsNil
) in the errors/abci_test.go
file. This suggests that these functions might not be explicitly tested.
To ensure comprehensive test coverage, it is important to add test cases that directly test these functions. Here are the specific locations in the codebase that need attention:
errors/abci.go
: FunctionsdebugErrEncoder
,defaultErrEncoder
,abciCode
,abciCodespace
,errIsNil
need direct test cases.errors/abci_test.go
: Add new test functions to cover the above-mentioned functions.
Please add the necessary test cases to ensure all error handling logic is thoroughly tested.
Analysis chain
Ensure comprehensive test coverage for new error handling logic.
The output shows that the errors/abci.go
file contains several functions related to error handling, such as ABCIInfo
, debugErrEncoder
, defaultErrEncoder
, abciCode
, abciCodespace
, and errIsNil
. The errors/abci_test.go
file includes two test functions: TestABCInfo
and TestABCIInfoSerializeErr
.
Both test functions seem to cover various scenarios for the ABCIInfo
function, including different types of errors and debug modes. However, there is no explicit indication that the other error handling functions (debugErrEncoder
, defaultErrEncoder
, abciCode
, abciCodespace
, errIsNil
) are directly tested.
To ensure comprehensive test coverage, we need to verify if these additional functions are tested either directly or indirectly through the existing test cases. Let's generate a script to search for references to these functions within the test file.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all new error handling logic in `errors/abci.go` is covered by tests in `errors/abci_test.go`.
# Test: Search for test cases covering new logic. Expect: Test cases found.
rg --type go 'Test' errors/abci_test.go
Length of output: 118
Script:
#!/bin/bash
# Description: Identify error handling logic in `errors/abci.go` and check if the test functions in `errors/abci_test.go` cover them.
# Step 1: Search for error handling logic in `errors/abci.go`.
rg --type go 'error' errors/abci.go
# Step 2: Display the content of `errors/abci_test.go` to cross-reference the test functions.
cat errors/abci_test.go
Length of output: 3763
Script:
#!/bin/bash
# Description: Verify if additional error handling functions in `errors/abci.go` are covered by tests in `errors/abci_test.go`.
# Step 1: Search for references to `debugErrEncoder` in `errors/abci_test.go`.
rg --type go 'debugErrEncoder' errors/abci_test.go
# Step 2: Search for references to `defaultErrEncoder` in `errors/abci_test.go`.
rg --type go 'defaultErrEncoder' errors/abci_test.go
# Step 3: Search for references to `abciCode` in `errors/abci_test.go`.
rg --type go 'abciCode' errors/abci_test.go
# Step 4: Search for references to `abciCodespace` in `errors/abci_test.go`.
rg --type go 'abciCodespace' errors/abci_test.go
# Step 5: Search for references to `errIsNil` in `errors/abci_test.go`.
rg --type go 'errIsNil' errors/abci_test.go
Length of output: 240
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Do we want to keep v1 around? Don't think we need it? |
Depends if we stop maintaining v1 |
Don't think we need to since we haven't touched the pkg much in the past few months |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this 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.yml
Review profile: CHILL
Files selected for processing (2)
- errors/CHANGELOG.md (1 hunks)
- errors/abci.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- errors/abci.go
Additional context used
Path-based instructions (1)
errors/CHANGELOG.md (1)
Pattern
**/*.md
: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"
LanguageTool
errors/CHANGELOG.md
[style] ~36-~36: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...es from the error package. This is done in order to keep the dependency graph of errors min...
Markdownlint
errors/CHANGELOG.md
37-37: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces
@@ -34,6 +34,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ | |||
### API Breaking | |||
|
|||
* [#20402](https://github.com/cosmos/cosmos-sdk/pull/20402) Remove Grpc error codes from the error package. This is done in order to keep the dependency graph of errors minimal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing for conciseness.
- This is done in order to keep the dependency graph of errors minimal
+ This simplifies the error dependency graph
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
* [#20402](https://github.com/cosmos/cosmos-sdk/pull/20402) Remove Grpc error codes from the error package. This is done in order to keep the dependency graph of errors minimal | |
* [#20402](https://github.com/cosmos/cosmos-sdk/pull/20402) Remove Grpc error codes from the error package. This simplifies the error dependency graph |
Tools
LanguageTool
[style] ~36-~36: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...es from the error package. This is done in order to keep the dependency graph of errors min...
@@ -34,6 +34,7 @@ | |||
### API Breaking | |||
|
|||
* [#20402](https://github.com/cosmos/cosmos-sdk/pull/20402) Remove Grpc error codes from the error package. This is done in order to keep the dependency graph of errors minimal | |||
* [#20539](https://github.com/cosmos/cosmos-sdk/pull/20539) v2 errors removes `IsOf`, `Recover`, `WithType` and wrapped error. The errors package uses the go std library errors. It provides a `Wrap` and `Wrapf` to help in the migration from v1 to v2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the trailing space at the end of the line.
- v2 errors removes `IsOf`, `Recover`, `WithType` and wrapped error. The errors package uses the go std library errors. It provides a `Wrap` and `Wrapf` to help in the migration from v1 to v2.
+ v2 errors removes `IsOf`, `Recover`, `WithType` and wrapped error. The errors package uses the go std library errors. It provides a `Wrap` and `Wrapf` to help in the migration from v1 to v2.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
* [#20539](https://github.com/cosmos/cosmos-sdk/pull/20539) v2 errors removes `IsOf`, `Recover`, `WithType` and wrapped error. The errors package uses the go std library errors. It provides a `Wrap` and `Wrapf` to help in the migration from v1 to v2. | |
* [#20539](https://github.com/cosmos/cosmos-sdk/pull/20539) v2 errors removes `IsOf`, `Recover`, `WithType` and wrapped error. The errors package uses the go std library errors. It provides a `Wrap` and `Wrapf` to help in the migration from v1 to v2. |
Tools
Markdownlint
37-37: Expected: 0 or 2; Actual: 1 (MD009, no-trailing-spaces)
Trailing spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I think you can remove handle.go
as well.
* main: refactor(x/auth): Fix system test (#20531) feat(crypto): add blst (#20296) docs: Update high level overview and introduction (#20535) refactor(x/core): remove test (#20624) feat(x/mint)!: Replace InflationCalculationFn with MintFn + simple epoch minting (#20363) docs: remove duplicate words (#20622) feat: prep for errors v2 (#20539) chore: reduce default inflation (#20606) refactor(store): add miss defer (#20602) chore: use comet api pkg instead of comet alias (#20614) chore: write gentx info to cmd.ErrOrStderr (#20616) docs: ADR 073: update to accepted and add to README.md (#20619) chore(proto): change future extracted modules version from v1.0.0 to v0.2.0 (#20600) fix: remove some duplicate words (#20605) feat(stf): port simappv2 changes (#20587) chore: bring patch changelogs to main (#20599)
Description
errors v2 is a no dep errors package to be used. It removes helpers that have been replaced by the go standard library
the errors package provides a way to register errors. If you would like to include a stack trace it must be set manually. Automatic stack traces was removed
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Refactor
testing.T
interface.Chores
CHANGELOG.md
to reflect recent changes and migration steps from version 1 to version 2 of the errors package.