Skip to content

Commit f7ff6bd

Browse files
(enhance): Enhance custom linter setuplogerrorcheck description (#1778)
1 parent 7146a7a commit f7ff6bd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

hack/ci/custom-linters/analyzers/setuplognilerrorcheck.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212

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

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

7374
pass.Reportf(callExpr.Pos(),
7475
"Incorrect usage of 'logger.Error(nil, ...)'. The first argument must be a non-nil 'error'. "+
75-
"Passing 'nil' results in silent failures, making debugging harder.\n\n"+
76+
"Passing 'nil' may hide error details, making debugging harder.\n\n"+
7677
"\U0001F41B **What is wrong?**\n %s\n\n"+
7778
"\U0001F4A1 **How to solve? Return the error, i.e.:**\n logger.Error(%s, %s, \"key\", value)\n\n",
7879
sourceLine, suggestedError, suggestedMessage)

hack/ci/custom-linters/analyzers/testdata/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func testLogger() {
1010
var value int
1111

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

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

0 commit comments

Comments
 (0)