Skip to content

🌱 (enhance): Enhance custom linter setuplogerrorcheck description #1778

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

var SetupLogErrorCheck = &analysis.Analyzer{
Name: "setuplogerrorcheck",
Doc: "Detects improper usage of logger.Error() calls, ensuring the first argument is a non-nil error.",
Run: runSetupLogErrorCheck,
Doc: "Detects and reports improper usages of logger.Error() calls to enforce good practices " +
"and prevent silent failures.",
Run: runSetupLogErrorCheck,
}

func runSetupLogErrorCheck(pass *analysis.Pass) (interface{}, error) {
Expand Down Expand Up @@ -72,7 +73,7 @@ func runSetupLogErrorCheck(pass *analysis.Pass) (interface{}, error) {

pass.Reportf(callExpr.Pos(),
"Incorrect usage of 'logger.Error(nil, ...)'. The first argument must be a non-nil 'error'. "+
"Passing 'nil' results in silent failures, making debugging harder.\n\n"+
"Passing 'nil' may hide error details, making debugging harder.\n\n"+
"\U0001F41B **What is wrong?**\n %s\n\n"+
"\U0001F4A1 **How to solve? Return the error, i.e.:**\n logger.Error(%s, %s, \"key\", value)\n\n",
sourceLine, suggestedError, suggestedMessage)
Expand Down
2 changes: 1 addition & 1 deletion hack/ci/custom-linters/analyzers/testdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func testLogger() {
var value int

// Case 1: Nil error - Ensures the first argument cannot be nil.
logger.Error(nil, "message") // want ".*results in silent failures, making debugging harder.*"
logger.Error(nil, "message") // want ".*may hide error details, making debugging harder*"

// Case 2: Odd number of key-value arguments - Ensures key-value pairs are complete.
logger.Error(err, "message", "key1") // want ".*Key-value pairs must be provided after the message, but an odd number of arguments was found.*"
Expand Down