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

[Tooling] Add protocheck status-errors subcmd to check for non-gRPC status error returns #929

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Nov 18, 2024

Summary

Adds a status-errors subcommand to protocheck which identifies msgServer methods and query handlers which don't return gRPC status error codes:

image

Issue

Type of change

Select one or more from the following:

Testing

  • Documentation: make docusaurus_start; only needed if you make doc changes
  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@bryanchriswhite bryanchriswhite added on-chain On-chain business logic code health Cleans up some code tooling Tooling - CLI, scripts, helpers, off-chain, etc... labels Nov 18, 2024
@bryanchriswhite bryanchriswhite self-assigned this Nov 18, 2024
"fmt"
"go/ast"
"go/types"
"log"

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.

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.

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Nov 18, 2024

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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tools/scripts/protocheck/cmd/status_errors.go Outdated Show resolved Hide resolved
tools/scripts/protocheck/cmd/status_errors.go Outdated Show resolved Hide resolved
// 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.

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

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.

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.

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.

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.

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.

@bryanchriswhite bryanchriswhite changed the title Issues/860/chore/grpc errors [Tooling] Add protocheck status-errors subcommand to check for non-gRPC status error returns Nov 18, 2024
@bryanchriswhite bryanchriswhite changed the title [Tooling] Add protocheck status-errors subcommand to check for non-gRPC status error returns [Tooling] Add protocheck status-errors subcmd to check for non-gRPC status error returns Nov 18, 2024
@bryanchriswhite bryanchriswhite linked an issue Nov 18, 2024 that may be closed by this pull request
7 tasks
go.mod Outdated
go 1.23.0
go 1.23
Copy link
Contributor Author

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... ?

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... ?

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.

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

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!

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!

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.

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...

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...

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,
)
Copy link
Contributor Author

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.

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...

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

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.

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...

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...

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?

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...

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...

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...

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...

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...

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...

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...

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.

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?

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...

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...

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...

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...

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...

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.

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.

@bryanchriswhite bryanchriswhite force-pushed the issues/860/chore/grpc-errors branch from 2702b60 to 3bbb3c9 Compare November 27, 2024 12:51
@bryanchriswhite bryanchriswhite force-pushed the issues/860/chore/grpc-errors branch from 3bbb3c9 to 4169627 Compare November 27, 2024 12:53
RunE: runStatusErrorsCheck,
}

// TODO_IN_THIS_COMMIT: refactor to avoid global logger var.

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...

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...

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...

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...

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...

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...

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...

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Cleans up some code on-chain On-chain business logic tooling Tooling - CLI, scripts, helpers, off-chain, etc...
Projects
Status: 🏗 In progress
2 participants