diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
| commit | 44a426c883a2c448d40a19903c822d03e5cf70af (patch) | |
| tree | dbb1fe11db1993c2cac7daf1c9930e37f44b38d1 /internal/platforms/linkedin/preview.go | |
| parent | cfddc5696f4956081630e3d394ef3d8c652af02e (diff) | |
chore: complete code quality audit fixesv1.2.6
- Fixed failing test in config_test.go (hardcoded date)
- Addressed unchecked error returns from Close() operations
- Refactored large functions to follow SRP (run.go and main.go)
- Added documentation to exported identifiers
- Fixed linting errors (error message capitalization, errcheck)
- Bumped version to v1.2.6
Diffstat (limited to 'internal/platforms/linkedin/preview.go')
| -rw-r--r-- | internal/platforms/linkedin/preview.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/internal/platforms/linkedin/preview.go b/internal/platforms/linkedin/preview.go index b7387c9..54c24ba 100644 --- a/internal/platforms/linkedin/preview.go +++ b/internal/platforms/linkedin/preview.go @@ -89,7 +89,12 @@ func (p preview) DownloadImage(destPath string) (string, error) { if err != nil { return "", err } - defer resp.Body.Close() + defer func() { + if err := resp.Body.Close(); err != nil { + // Log the error but don't fail the operation since we've already read the data + colour.Errorln("Error closing response body:", err) + } + }() if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("bad status while trying to download image: %s", resp.Status) @@ -100,7 +105,12 @@ func (p preview) DownloadImage(destPath string) (string, error) { if err != nil { return destFile, fmt.Errorf("%s: %w", destFile, err) } - defer out.Close() + defer func() { + if err := out.Close(); err != nil { + // Log the error but don't fail the operation since we've already written the data + colour.Errorln("Error closing output file:", err) + } + }() _, err = io.Copy(out, resp.Body) if err != nil { @@ -177,7 +187,12 @@ func extractFromURL(ctx context.Context, url string) (string, string, error) { if err != nil { return "", "", fmt.Errorf("failed to get URL: %w", err) } - defer resp.Body.Close() + defer func() { + if err := resp.Body.Close(); err != nil { + // Log the error but don't fail the operation since we've already read the data + colour.Errorln("Error closing response body:", err) + } + }() if resp.StatusCode != http.StatusOK { return "", "", fmt.Errorf("failed to get a successful response: %v", resp.StatusCode) |
