-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Tooling] Add protocheck status-errors
subcmd to check for non-gRPC status error returns
#929
base: main
Are you sure you want to change the base?
Conversation
"fmt" | ||
"go/ast" | ||
"go/types" | ||
"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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
"log"
rootCmd.AddCommand(statusErrorsCheckCmd) | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: pre-run: drop patch version in go.mod; post-run: restore. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: pre-run: drop patch version in go.mod; post-run: restore.
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.
UPDATE: No need to do this. The reason I had to do this was because I had an old version (1.20.x) of go in my path which was being used by golang.org/x/tools/packages
. Pre 1.21.x, go.mod version did not have a patch version.
func runStatusErrorsCheck(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
|
||
// TODO_IN_THIS_COMMIT: add hack/work-around to temporarily strip patch version from go.mod. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: add hack/work-around to temporarily strip patch version from go.mod.
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.
// TODO_IN_THIS_COMMIT: add hack/work-around to temporarily strip patch version from go.mod. | ||
// TODO_IN_THIS_COMMIT: add hack/work-around to temporarily strip patch version from go.mod. | ||
|
||
// TODO_IN_THIS_COMMIT: to support this, need to load all modules but only inspect target module. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: to support this, need to load all modules but only inspect target module.
} | ||
// --- END | ||
|
||
// TODO_IN_THIS_COMMIT: extract --- BEGIN |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: extract --- BEGIN
// --- END | ||
|
||
// TODO_IN_THIS_COMMIT: extract --- BEGIN | ||
// TODO_IN_THIS_COMMIT: figure out why there are duplicate offending lines. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: figure out why there are duplicate offending lines.
// TODO_IN_THIS_COMMIT: extract --- BEGIN | ||
// TODO_IN_THIS_COMMIT: figure out why there are duplicate offending lines. | ||
// Print offending lines in package | ||
// TODO_IN_THIS_COMMIT: refactor to const. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: refactor to const.
return | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: Implement & log when this happens. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: Implement & log when this happens.
return strings.Repeat(" ", indent) | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: remove or move to a testutil package. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: remove or move to a testutil package.
protocheck status-errors
subcommand to check for non-gRPC status error returns
protocheck status-errors
subcommand to check for non-gRPC status error returnsprotocheck status-errors
subcmd to check for non-gRPC status error returns
go.mod
Outdated
go 1.23.0 | ||
go 1.23 |
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.
Revert.
} | ||
//logger.Debug().Msgf("tracing expression args: %+v", expr) | ||
//for _, arg := range expr.Args { | ||
// // TODO_IN_THIS_COMMIT: return traceExpressionStack... ? |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// // TODO_IN_THIS_COMMIT: return traceExpressionStack... ?
return true | ||
case *ast.BinaryExpr: | ||
logger.Debug().Msg("tracing binary expression") | ||
// TODO_IN_THIS_COMMIT: return traceExpressionStack... ? |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: return traceExpressionStack... ?
var ( | ||
flagModule = "module" | ||
flagModuleShorthand = "m" | ||
// TODO_IN_THIS_COMMIT: support this flag. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: support this flag.
return nil | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: 2-step check |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: 2-step check
//fmt.Printf(">>> filenames:\n%s\n", strings.Join(filenames, "\n")) | ||
|
||
// TODO_IN_THIS_COMMIT: extract --- BEGIN | ||
// TODO_IN_THIS_COMMIT: check the filename and only inspect each once! |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: check the filename and only inspect each once!
continue | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: remove! |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: remove!
return false | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: figure out why this file hangs the command. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: figure out why this file hangs the command.
) | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
@@ -50,3 +50,11 @@ func WithSetupFn(fn func(logger *zerolog.Logger)) polylog.LoggerOption { | |||
fn(&logger.(*zerologLogger).Logger) | |||
} | |||
} | |||
|
|||
// TODO_IN_THIS_COMMIT: godoc & test... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: godoc & test...
msg, | ||
strings.Join(offendingPkgErrLines, "\n"), | ||
msg, | ||
) |
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.
// TODO_IN_THIS_COMMIT: add, set, & return non-zero exit code.
func runStatusErrorsCheck(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
|
||
// TODO_IN_THIS_COMMIT: extract to validation function. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: extract to validation function.
|
||
var TRACE bool | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
// "inspectPosition": pkg.Fset.Position(lastReturnArgNode.Pos()).String(), | ||
//}).Msg("traversing ast node") | ||
|
||
// TODO_IN_THIS_COMMIT: No need to check that the last return |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: No need to check that the last return
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: refactor; below happens when the selector is not found within any package. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: refactor; below happens when the selector is not found within any package.
case *ast.Ident: | ||
logger.Debug().Str("name", expr.Name).Msg("tracing ident") | ||
//def := candidatePkg.TypesInfo.Defs[expr] | ||
// TODO_IN_THIS_COMMIT: handle no def... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: handle no def...
//def := candidatePkg.TypesInfo.Defs[expr] | ||
// TODO_IN_THIS_COMMIT: handle no def... | ||
//x := def.Parent().Lookup(expr.Name) | ||
// TODO_IN_THIS_COMMIT: handle no lookup... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: handle no lookup...
// traceExpressionStack(doa, pkgs, expr, candidatePkg, candidateNode, offendingPositions) | ||
//case *ast.AssignStmt: | ||
// logger.Debug().Msgf(">>>>>>> assign stmt: %+v", doa) | ||
// // TODO_IN_THIS_COMMIT: what about len(Rhs) > 1? |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// // TODO_IN_THIS_COMMIT: what about len(Rhs) > 1?
logger.Debug().Msgf("no declaration or assignment found for ident %q", targetIdent.String()) | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: improve comment... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: improve comment...
} | ||
|
||
if len(assignsRhs) > 0 { | ||
// TODO_IN_THIS_COMMIT: comment explaining what's going on here... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: comment explaining what's going on here...
return declNode, declPos | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
return declOrAssign, &foundPos | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: refactor... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: refactor...
"github.com/pokt-network/poktroll/pkg/polylog" | ||
) | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
|
||
const grpcStatusImportPath = "google.golang.org/grpc/status" | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
const grpcStatusImportPath = "google.golang.org/grpc/status" | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... | ||
// TODO_IN_THIS_COMMIT: detemine whether this actually needs to return anything. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: detemine whether this actually needs to return anything.
logger.Debug().Send() | ||
|
||
// Search for the selector expression in all module packages. | ||
// TODO_IN_THIS_COMMIT: is it expected and/or guaranteed that it will only be found in one pkg? |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: is it expected and/or guaranteed that it will only be found in one pkg?
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: note early return... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: note early return...
return false | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
return nil | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
offendingPkgErrLineSet[sourceLine] = struct{}{} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... exits with code CodeNonStatusGRPCErrorsFound if offending lines found if offending lines found. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc... exits with code CodeNonStatusGRPCErrorsFound if offending lines found if offending lines found.
2702b60
to
3bbb3c9
Compare
3bbb3c9
to
4169627
Compare
RunE: runStatusErrorsCheck, | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: refactor to avoid global logger var. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: refactor to avoid global logger var.
Tests: false, | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: update comment... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: update comment...
return nil | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
return nil | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
return false | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
return nil | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
offendingPkgErrLineSet[sourceLine] = struct{}{} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc...
} | ||
} | ||
|
||
// TODO_IN_THIS_COMMIT: move & godoc... exits with code CodeNonStatusGRPCErrorsFound if offending lines found if offending lines found. |
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.
[linter-name (fail-on-found)] reported by reviewdog 🐶
// TODO_IN_THIS_COMMIT: move & godoc... exits with code CodeNonStatusGRPCErrorsFound if offending lines found if offending lines found.
Summary
Adds a
status-errors
subcommand toprotocheck
which identifiesmsgServer
methods and query handlers which don't return gRPC status error codes:Issue
Type of change
Select one or more from the following:
consensus-breaking
label if so. See [Infra] Automatically add theconsensus-breaking
label #791 for detailsTesting
make docusaurus_start
; only needed if you make doc changesmake go_develop_and_test
make test_e2e
devnet-test-e2e
label to the PR.Sanity Checklist