From c83606908f969c59949dd2c0e4ff9eaf8e364e42 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Sat, 9 May 2026 02:05:40 +0000 Subject: [PATCH] lint: fix errcheck in api/api.go debug log writes Add lint.Fprintf and lint.Write helpers for safe writer operations. Use lint.Fprintf for unchecked fmt.Fprintf calls in webhookFieldseeker. --- api/api.go | 6 +++--- lint/error.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index 358fb6e8..dffd8a17 100644 --- a/api/api.go +++ b/api/api.go @@ -294,7 +294,7 @@ func webhookFieldseeker(w http.ResponseWriter, r *http.Request) { } for name, values := range r.Header { for _, value := range values { - fmt.Fprintf(file, "%s: %s\n", name, value) + lint.Fprintf(file, "%s: %s\n", name, value) } } @@ -323,11 +323,11 @@ func webhookFieldseeker(w http.ResponseWriter, r *http.Request) { } if len(body) == 0 { - fmt.Fprintf(file, "(empty body)") + lint.Fprintf(file, "(empty body)") } } - fmt.Fprintf(file, "\n=== End of request ===\n\n") + lint.Fprintf(file, "\n=== End of request ===\n\n") // Extract the crc_token value for the signature portion diff --git a/lint/error.go b/lint/error.go index ae76d3ba..37e634ee 100644 --- a/lint/error.go +++ b/lint/error.go @@ -2,6 +2,8 @@ package lint import ( "context" + "fmt" + "io" "github.com/rs/zerolog/log" ) @@ -33,3 +35,19 @@ func LogOnErrRollback(f ErrorableCtx, ctx context.Context, msg string) { log.Error().Err(e).Msg(msg) } } + +// Fprintf writes a formatted string to w, logging any error. +func Fprintf(w io.Writer, format string, args ...any) { + _, err := fmt.Fprintf(w, format, args...) + if err != nil { + log.Error().Err(err).Msg("fprintf failed") + } +} + +// Write writes p to w, logging any error. +func Write(w io.Writer, p []byte) { + _, err := w.Write(p) + if err != nil { + log.Error().Err(err).Msg("write failed") + } +}