From 207340dfc3da381f65a19b70002bfa9e784bee45 Mon Sep 17 00:00:00 2001 From: "Tomi P. Hakala" Date: Sat, 28 Dec 2024 19:20:49 +0200 Subject: [PATCH] fix: improve error handling in file analysis by using error wrapping - Updated the error handling in FileAnalysis to use %w for wrapping errors when writing partial results. - Simplified the condition for checking notes before writing results. --- internal/analysis/file.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/analysis/file.go b/internal/analysis/file.go index 010e315..41a87ec 100644 --- a/internal/analysis/file.go +++ b/internal/analysis/file.go @@ -34,11 +34,11 @@ func FileAnalysis(settings *conf.Settings) error { notes, err := processAudioFile(settings, &audioInfo) if err != nil { // If we have partial results, write them before returning the error - if notes != nil && len(notes) > 0 { + if len(notes) > 0 { fmt.Printf("\n\033[33m⚠️ Writing partial results before exiting due to error\033[0m\n") if writeErr := writeResults(settings, notes); writeErr != nil { - // Combine both errors in the return message - return fmt.Errorf("analysis error: %v; failed to write partial results: %v", err, writeErr) + // Changed to use %w for error wrapping + return fmt.Errorf("analysis error: %w; failed to write partial results: %w", err, writeErr) } } return err