fix: explicitly ignore Close() errors in error paths and retry loops

This commit is contained in:
程智超0668000959
2026-06-25 15:38:41 +08:00
parent dff16dbb91
commit 62a2b0015a
4 changed files with 22 additions and 22 deletions
+6 -6
View File
@@ -569,7 +569,7 @@ func (t *ExecTool) runBackground(ctx context.Context, command, cwd string, ptyEn
// with synchronous exec runs.
if err := isolation.Start(cmd); err != nil {
if session.ptyMaster != nil {
session.ptyMaster.Close()
_ = session.ptyMaster.Close()
}
return ErrorResult(fmt.Sprintf("failed to start command: %v", err))
}
@@ -696,11 +696,11 @@ func (t *ExecTool) runBackground(ctx context.Context, command, cwd string, ptyEn
}
}
// All pipes closed, get exit status
if stdinWriter != nil {
stdinWriter.Close()
}
cmd.Wait()
// All pipes closed, get exit status
if stdinWriter != nil {
_ = stdinWriter.Close()
}
cmd.Wait()
session.mu.Lock()
if cmd.ProcessState != nil {
+13 -13
View File
@@ -574,19 +574,19 @@ func extractZip(archivePath, destDir string) error {
if err != nil {
return err
}
out, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, f.FileInfo().Mode())
if err != nil {
rc.Close()
return err
}
if _, err := io.Copy(out, rc); err != nil {
rc.Close()
out.Close()
return err
}
if err := rc.Close(); err != nil {
out.Close()
return fmt.Errorf("close zip entry reader: %w", err)
out, err := os.OpenFile(target, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, f.FileInfo().Mode())
if err != nil {
_ = rc.Close()
return err
}
if _, err := io.Copy(out, rc); err != nil {
_ = rc.Close()
_ = out.Close()
return err
}
if err := rc.Close(); err != nil {
_ = out.Close()
return fmt.Errorf("close zip entry reader: %w", err)
}
if err := out.Close(); err != nil {
return fmt.Errorf("close extracted file %q: %w", target, err)
+2 -2
View File
@@ -26,7 +26,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
for i := range maxRetries {
if i > 0 && resp != nil {
resp.Body.Close()
_ = resp.Body.Close()
}
resp, err = client.Do(req)
@@ -42,7 +42,7 @@ func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response,
if i < maxRetries-1 {
if err = sleepWithCtx(req.Context(), retryDelayForAttempt(resp, i)); err != nil {
if resp != nil {
resp.Body.Close()
_ = resp.Body.Close()
}
return nil, fmt.Errorf("failed to sleep: %w", err)
}
+1 -1
View File
@@ -176,7 +176,7 @@ func DownloadFile(urlStr, filename string, opts DownloadOptions) string {
}
if _, err := io.Copy(out, resp.Body); err != nil {
out.Close()
_ = out.Close()
os.Remove(localPath)
logger.ErrorCF(opts.LoggerPrefix, "Failed to write file", map[string]any{
"error": err.Error(),