-
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
chore: move abci errors to baseapp #20756
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -166,7 +166,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci | |||||
// Ref: https://github.com/cosmos/cosmos-sdk/pull/8039 | ||||||
defer func() { | ||||||
if r := recover(); r != nil { | ||||||
resp = sdkerrors.QueryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace) | ||||||
resp = queryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to use a more descriptive error message. The error message in - resp = queryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "%v", r), app.trace)
+ resp = queryResult(errorsmod.Wrapf(sdkerrors.ErrPanic, "Query recovery from panic: %v", r), app.trace) Committable suggestion
Suggested change
|
||||||
} | ||||||
}() | ||||||
|
||||||
|
@@ -180,7 +180,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci | |||||
defer telemetry.MeasureSince(telemetry.Now(), req.Path) | ||||||
|
||||||
if req.Path == QueryPathBroadcastTx { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil | ||||||
return queryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider improving error message clarity. The error message "can't route a broadcast tx message" could be more specific to explain why the routing cannot be done. - return queryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "can't route a broadcast tx message"), app.trace), nil
+ return queryResult(errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "BroadcastTx messages are not supported in this context"), app.trace), nil Committable suggestion
Suggested change
|
||||||
} | ||||||
|
||||||
// handle gRPC routes first rather than calling splitPath because '/' characters | ||||||
|
@@ -191,7 +191,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci | |||||
|
||||||
path := SplitABCIQueryPath(req.Path) | ||||||
if len(path) == 0 { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace), nil | ||||||
return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace), nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error message for better user guidance. The error message "no query path provided" could provide guidance on what paths are expected. - return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "no query path provided"), app.trace), nil
+ return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "No query path provided. Please specify a valid query path."), app.trace), nil Committable suggestion
Suggested change
|
||||||
} | ||||||
|
||||||
switch path[0] { | ||||||
|
@@ -206,7 +206,7 @@ func (app *BaseApp) Query(_ context.Context, req *abci.QueryRequest) (resp *abci | |||||
resp = handleQueryP2P(app, path) | ||||||
|
||||||
default: | ||||||
resp = sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace) | ||||||
resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error message for unknown paths. The error message could be more informative by suggesting possible correct paths. - resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "unknown query path"), app.trace)
+ resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "Unknown query path. Please refer to the documentation for supported paths."), app.trace) Committable suggestion
Suggested change
|
||||||
} | ||||||
|
||||||
return resp, nil | ||||||
|
@@ -365,7 +365,7 @@ func (app *BaseApp) CheckTx(req *abci.CheckTxRequest) (*abci.CheckTxResponse, er | |||||
|
||||||
gInfo, result, anteEvents, err := app.runTx(mode, req.Tx) | ||||||
if err != nil { | ||||||
return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil | ||||||
return responseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Inconsistent use of The function
Please ensure that Analysis chainEnsure consistency in error handling. The function Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify consistent use of `responseCheckTxWithEvents` across similar contexts.
# Test: Search for `responseCheckTxWithEvents` usage. Expect: Consistent usage in similar error handling contexts.
rg --type go 'responseCheckTxWithEvents'
Length of output: 396 Script: #!/bin/bash
# Description: Retrieve the definition of `responseCheckTxWithEvents` to understand its purpose and usage.
# Extract the function definition of `responseCheckTxWithEvents` from baseapp/errors.go
ast-grep --lang go --pattern 'func responseCheckTxWithEvents($_, $_, $_, $_, $_) $_ { $$$ }' baseapp/errors.go
Length of output: 112 Script: #!/bin/bash
# Description: Retrieve the definition of `responseCheckTxWithEvents` to understand its purpose and usage.
# Search for the function definition of `responseCheckTxWithEvents` in baseapp/errors.go and extract the relevant lines.
rg 'func responseCheckTxWithEvents' baseapp/errors.go -A 20
Length of output: 807 Script: #!/bin/bash
# Description: Verify consistent use of `responseCheckTxWithEvents` across similar contexts.
# Search for functions that handle errors and return responses in the codebase.
rg --type go 'return &abci\.(CheckTxResponse|ExecTxResult)' -A 5
Length of output: 1267 |
||||||
} | ||||||
|
||||||
return &abci.CheckTxResponse{ | ||||||
|
@@ -825,7 +825,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz | |||||
// In the case where a transaction included in a block proposal is malformed, | ||||||
// we still want to return a default response to comet. This is because comet | ||||||
// expects a response for each transaction included in a block proposal. | ||||||
response = sdkerrors.ResponseExecTxResultWithEvents( | ||||||
response = responseExecTxResultWithEvents( | ||||||
sdkerrors.ErrTxDecode, | ||||||
0, | ||||||
0, | ||||||
|
@@ -1023,7 +1023,7 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q | |||||
|
||||||
gInfo, res, err := app.Simulate(txBytes) | ||||||
if err != nil { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(err, "failed to simulate tx"), app.trace) | ||||||
return queryResult(errorsmod.Wrap(err, "failed to simulate tx"), app.trace) | ||||||
} | ||||||
|
||||||
simRes := &sdk.SimulationResponse{ | ||||||
|
@@ -1033,7 +1033,7 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q | |||||
|
||||||
bz, err := codec.ProtoMarshalJSON(simRes, app.interfaceRegistry) | ||||||
if err != nil { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(err, "failed to JSON encode simulation response"), app.trace) | ||||||
return queryResult(errorsmod.Wrap(err, "failed to JSON encode simulation response"), app.trace) | ||||||
} | ||||||
|
||||||
return &abci.QueryResponse{ | ||||||
|
@@ -1050,11 +1050,11 @@ func handleQueryApp(app *BaseApp, path []string, req *abci.QueryRequest) *abci.Q | |||||
} | ||||||
|
||||||
default: | ||||||
return sdkerrors.QueryResult(errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path), app.trace) | ||||||
return queryResult(errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path), app.trace) | ||||||
} | ||||||
} | ||||||
|
||||||
return sdkerrors.QueryResult( | ||||||
return queryResult( | ||||||
errorsmod.Wrap( | ||||||
sdkerrors.ErrUnknownRequest, | ||||||
"expected second parameter to be either 'simulate' or 'version', neither was present", | ||||||
|
@@ -1065,13 +1065,13 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. | |||||
// "/store" prefix for store queries | ||||||
queryable, ok := app.cms.(storetypes.Queryable) | ||||||
if !ok { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "multi-store does not support queries"), app.trace) | ||||||
return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "multi-store does not support queries"), app.trace) | ||||||
} | ||||||
|
||||||
req.Path = "/" + strings.Join(path[1:], "/") | ||||||
|
||||||
if req.Height <= 1 && req.Prove { | ||||||
return sdkerrors.QueryResult( | ||||||
return queryResult( | ||||||
errorsmod.Wrap( | ||||||
sdkerrors.ErrInvalidRequest, | ||||||
"cannot query with proof when height <= 1; please provide a valid height", | ||||||
|
@@ -1081,7 +1081,7 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. | |||||
sdkReq := storetypes.RequestQuery(req) | ||||||
resp, err := queryable.Query(&sdkReq) | ||||||
if err != nil { | ||||||
return sdkerrors.QueryResult(err, app.trace) | ||||||
return queryResult(err, app.trace) | ||||||
} | ||||||
resp.Height = req.Height | ||||||
|
||||||
|
@@ -1093,7 +1093,7 @@ func handleQueryStore(app *BaseApp, path []string, req abci.QueryRequest) *abci. | |||||
func handleQueryP2P(app *BaseApp, path []string) *abci.QueryResponse { | ||||||
// "/p2p" prefix for p2p queries | ||||||
if len(path) < 4 { | ||||||
return sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>"), app.trace) | ||||||
return queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>"), app.trace) | ||||||
} | ||||||
|
||||||
var resp *abci.QueryResponse | ||||||
|
@@ -1110,7 +1110,7 @@ func handleQueryP2P(app *BaseApp, path []string) *abci.QueryResponse { | |||||
} | ||||||
|
||||||
default: | ||||||
resp = sdkerrors.QueryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace) | ||||||
resp = queryResult(errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace) | ||||||
} | ||||||
|
||||||
return resp | ||||||
|
@@ -1166,12 +1166,12 @@ func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Con | |||||
func (app *BaseApp) handleQueryGRPC(handler GRPCQueryHandler, req *abci.QueryRequest) *abci.QueryResponse { | ||||||
ctx, err := app.CreateQueryContext(req.Height, req.Prove) | ||||||
if err != nil { | ||||||
return sdkerrors.QueryResult(err, app.trace) | ||||||
return queryResult(err, app.trace) | ||||||
} | ||||||
|
||||||
resp, err := handler(ctx, req) | ||||||
if err != nil { | ||||||
resp = sdkerrors.QueryResult(gRPCErrorToSDKError(err), app.trace) | ||||||
resp = queryResult(gRPCErrorToSDKError(err), app.trace) | ||||||
resp.Height = req.Height | ||||||
return resp | ||||||
} | ||||||
|
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.
Fix trailing spaces in the CHANGELOG entry.
There's a markdown lint issue due to trailing spaces at the end of the entry. It's important to adhere to markdown best practices to maintain the quality of the documentation.
Committable suggestion