From bf3359057d1cf2dec99650162a5a622486541bab Mon Sep 17 00:00:00 2001 From: Md Mushfiqur Rahim <20mahin2020@gmail.com> Date: Mon, 25 May 2026 00:06:09 +0600 Subject: [PATCH] fix(view): log debug file errors (#1340) ## What? Logs write and close errors when writing debug image protocol output to files. The debug logger now wraps `WriteString` and `Close` calls for both `DEBUG_IMAGE_PROTOCOL_LOG` and `DEBUG_KITTY_LOG`, while keeping the existing `os.OpenFile` security lint annotations. ## Why? Closes #751. Ignoring file write and close errors can hide failures in debug logging and make image protocol issues harder to diagnose. Logging these errors through `loglevel.Debugf` keeps failures visible without changing normal runtime behavior. --------- Co-authored-by: FromSi --- view/html.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/view/html.go b/view/html.go index 9071182b3e8988916af0cc679ff69237502c4549..3600677dc000c9022bf5af564363f45807c7c006 100644 --- a/view/html.go +++ b/view/html.go @@ -266,13 +266,21 @@ func debugImageProtocol(format string, args ...interface{}) { loglevel.Infof("%s", strings.TrimSuffix(msg, "\n")) if path := os.Getenv("DEBUG_IMAGE_PROTOCOL_LOG"); path != "" { if f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil { //nolint:gosec - _, _ = f.WriteString(msg) - _ = f.Close() + if _, err := f.WriteString(msg); err != nil { + loglevel.Debugf("image protocol write error: %v", err) + } + if err := f.Close(); err != nil { + loglevel.Debugf("image protocol close error: %v", err) + } } } else if path := os.Getenv("DEBUG_KITTY_LOG"); path != "" { if f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil { //nolint:gosec - _, _ = f.WriteString(msg) - _ = f.Close() + if _, err := f.WriteString(msg); err != nil { + loglevel.Debugf("image protocol write error: %v", err) + } + if err := f.Close(); err != nil { + loglevel.Debugf("image protocol close error: %v", err) + } } } }