Skip to content

Commit

Permalink
fix: improve error handling in file analysis by using error wrapping
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
tphakala committed Dec 28, 2024
1 parent cccee8b commit 207340d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/analysis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 207340d

Please sign in to comment.