diff --git a/hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go b/hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go index 6eae8aa1e..ba9098a5f 100644 --- a/hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go +++ b/hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go @@ -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) { @@ -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) diff --git a/hack/ci/custom-linters/analyzers/testdata/main.go b/hack/ci/custom-linters/analyzers/testdata/main.go index 0a02ed939..97e712f50 100644 --- a/hack/ci/custom-linters/analyzers/testdata/main.go +++ b/hack/ci/custom-linters/analyzers/testdata/main.go @@ -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.*"