summaryrefslogtreecommitdiff
path: root/internal/image
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-08 08:38:05 +0200
committerPaul Buetow <paul@buetow.org>2026-03-08 08:38:05 +0200
commit3a255c0c64f858d5c05797aba9a6d159b0c7d82f (patch)
treedf517cfa866c3ba344c443f5c42a3c1e932ff0dd /internal/image
parentffa8e0bab35e430ed0e23ccc2383d56559924acc (diff)
fix(task-373): handle runtime cleanup errors in production paths
Diffstat (limited to 'internal/image')
-rw-r--r--internal/image/download.go10
-rw-r--r--internal/image/openai.go4
2 files changed, 10 insertions, 4 deletions
diff --git a/internal/image/download.go b/internal/image/download.go
index 8ea897e..b2af843 100644
--- a/internal/image/download.go
+++ b/internal/image/download.go
@@ -46,8 +46,8 @@ func NewDownloader(searcher ImageSearcher, options *DownloadOptions) *Downloader
}
}
-// DownloadImage downloads a single image to the specified path
-func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, outputPath string) error {
+// DownloadImage downloads a single image to the specified path.
+func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, outputPath string) (err error) {
// Ensure directory exists
dir := filepath.Dir(outputPath)
if dir != "" && dir != "." {
@@ -77,7 +77,11 @@ func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, ou
if err != nil {
return fmt.Errorf("create output file %q: %w", outputPath, err)
}
- defer file.Close()
+ defer func() {
+ if closeErr := file.Close(); err == nil && closeErr != nil {
+ err = fmt.Errorf("close output file %q: %w", outputPath, closeErr)
+ }
+ }()
// Copy with size limit if specified
var written int64
diff --git a/internal/image/openai.go b/internal/image/openai.go
index 5bb7db4..f2db41d 100644
--- a/internal/image/openai.go
+++ b/internal/image/openai.go
@@ -197,7 +197,9 @@ func (c *OpenAIClient) Download(ctx context.Context, url string) (io.ReadCloser,
}
if resp.StatusCode != http.StatusOK {
- resp.Body.Close()
+ if closeErr := resp.Body.Close(); closeErr != nil {
+ return nil, fmt.Errorf("HTTP %d: %s (failed to close response body: %v)", resp.StatusCode, resp.Status, closeErr)
+ }
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, resp.Status)
}