Skip to content

Commit 852cd7e

Browse files
committed
fix(workflows): handle all os.Stat errors and suppress cover art logging
- Replace os.IsNotExist checks with full error handling in Hugo and Standalone workflow validation; catches permission errors, broken symlinks, and I/O failures early - Pass nil to cli.PrintCover callback in main.go to suppress logging during Bubble Tea UI rendering and prevent stdout corruption of progress display - Update tests for both workflow implementations Signed-off-by: Martin Wimpress <code@wimpress.io>
1 parent ab89a75 commit 852cd7e

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

cmd/jivedrop/hugo.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ func (h *HugoWorkflow) Validate() error {
2828
return fmt.Errorf("episode markdown file must have .md extension: %s", CLI.EpisodeMD)
2929
}
3030

31-
// Validate audio file exists
32-
if _, err := os.Stat(CLI.AudioFile); os.IsNotExist(err) {
33-
return fmt.Errorf("audio file not found: %s", CLI.AudioFile)
31+
// Validate audio file exists and is accessible
32+
if _, err := os.Stat(CLI.AudioFile); err != nil {
33+
return fmt.Errorf("audio file not accessible: %w", err)
3434
}
3535

36-
// Validate episode markdown file exists
37-
if _, err := os.Stat(CLI.EpisodeMD); os.IsNotExist(err) {
38-
return fmt.Errorf("episode file not found: %s", CLI.EpisodeMD)
36+
// Validate episode markdown file exists and is accessible
37+
if _, err := os.Stat(CLI.EpisodeMD); err != nil {
38+
return fmt.Errorf("episode file not accessible: %w", err)
3939
}
4040

4141
// Validate custom cover art exists (if specified)
4242
if CLI.Cover != "" {
43-
if _, err := os.Stat(CLI.Cover); os.IsNotExist(err) {
44-
return fmt.Errorf("cover art not found: %s", CLI.Cover)
43+
if _, err := os.Stat(CLI.Cover); err != nil {
44+
return fmt.Errorf("cover art not accessible: %w", err)
4545
}
4646
}
4747

cmd/jivedrop/hugo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestHugoWorkflowValidate(t *testing.T) {
188188

189189
// For valid cases we only check argument validation, not file existence.
190190
// File-not-found errors are acceptable here since the files do not exist on disk.
191-
if err != nil && !strings.Contains(err.Error(), "not found") {
191+
if err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "not accessible") {
192192
t.Errorf("HugoWorkflow.Validate() unexpected error: %v (EpisodeMD=%q)", err, tt.episodeMD)
193193
}
194194
})
@@ -270,7 +270,7 @@ func TestHugoWorkflowValidate_Integration(t *testing.T) {
270270
t.Errorf("HugoWorkflow.Validate() expected error but got nil\n Description: %s\n EpisodeMD=%q",
271271
tt.description, tt.episodeMD)
272272
}
273-
if !tt.wantErr && err != nil && !strings.Contains(err.Error(), "not found") {
273+
if !tt.wantErr && err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "not accessible") {
274274
t.Errorf("HugoWorkflow.Validate() unexpected error: %v\n Description: %s\n EpisodeMD=%q",
275275
err, tt.description, tt.episodeMD)
276276
}

cmd/jivedrop/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func encode(mode WorkflowMode, tagInfo id3.TagInfo, coverArtPath, outputPath str
219219
return
220220
}
221221

222-
artwork, artErr := id3.ScaleCoverArt(coverArtPath, cli.PrintCover)
222+
artwork, artErr := id3.ScaleCoverArt(coverArtPath, nil)
223223
coverArtChan <- coverArtResult{data: artwork, err: artErr}
224224
}()
225225

cmd/jivedrop/standalone.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func (s *StandaloneWorkflow) Validate() error {
2828
return fmt.Errorf("standalone mode requires --cover flag (cover art path)")
2929
}
3030

31-
// Validate audio file exists
32-
if _, err := os.Stat(CLI.AudioFile); os.IsNotExist(err) {
33-
return fmt.Errorf("audio file not found: %s", CLI.AudioFile)
31+
// Validate audio file exists and is accessible
32+
if _, err := os.Stat(CLI.AudioFile); err != nil {
33+
return fmt.Errorf("audio file not accessible: %w", err)
3434
}
3535

36-
// Validate cover art exists
37-
if _, err := os.Stat(CLI.Cover); os.IsNotExist(err) {
38-
return fmt.Errorf("cover art not found: %s", CLI.Cover)
36+
// Validate cover art exists and is accessible
37+
if _, err := os.Stat(CLI.Cover); err != nil {
38+
return fmt.Errorf("cover art not accessible: %w", err)
3939
}
4040

4141
return nil

cmd/jivedrop/standalone_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestStandaloneWorkflowValidate(t *testing.T) {
251251

252252
// For valid cases we only check argument validation, not file existence.
253253
// File-not-found errors are acceptable here since the cover files do not exist on disk.
254-
if err != nil && !strings.Contains(err.Error(), "not found") {
254+
if err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "not accessible") {
255255
t.Errorf("StandaloneWorkflow.Validate() unexpected error: %v\n Title=%q, Num=%q, Cover=%q",
256256
err, tt.title, tt.num, tt.cover)
257257
}
@@ -364,7 +364,7 @@ func TestStandaloneWorkflowValidate_Integration(t *testing.T) {
364364
t.Errorf("StandaloneWorkflow.Validate() expected error but got nil\n Description: %s\n Title=%q, Num=%q, Cover=%q",
365365
tt.description, tt.title, tt.num, tt.cover)
366366
}
367-
if !tt.wantErr && err != nil && !strings.Contains(err.Error(), "not found") {
367+
if !tt.wantErr && err != nil && !strings.Contains(err.Error(), "not found") && !strings.Contains(err.Error(), "not accessible") {
368368
t.Errorf("StandaloneWorkflow.Validate() unexpected error: %v\n Description: %s\n Title=%q, Num=%q, Cover=%q",
369369
err, tt.description, tt.title, tt.num, tt.cover)
370370
}

0 commit comments

Comments
 (0)