From aa733f9a86b02d7b4d6edd8022a44e4ba417b24c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 8 Mar 2026 08:41:59 +0200 Subject: test(task-374): fix errcheck issues in tests and support code --- internal/gui/app.go | 16 ++++++++++++---- internal/gui/generator.go | 4 +++- internal/gui/widgets.go | 12 ++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'internal/gui') diff --git a/internal/gui/app.go b/internal/gui/app.go index c65cb42..5d37879 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -146,7 +146,9 @@ func New(config *Config) *Application { } // Ensure output directory exists - os.MkdirAll(config.OutputDir, 0755) + if err := os.MkdirAll(config.OutputDir, 0755); err != nil { + fmt.Fprintf(os.Stderr, "Warning: failed to create output directory %q: %v\n", config.OutputDir, err) + } ctx, cancel := context.WithCancel(context.Background()) @@ -629,7 +631,9 @@ func (a *Application) generateMaterials(word string) { if translation != "" { translationFile := filepath.Join(cardDir, "translation.txt") content := fmt.Sprintf("%s = %s\n", word, translation) - os.WriteFile(translationFile, []byte(content), 0644) + if err := os.WriteFile(translationFile, []byte(content), 0644); err != nil { + fmt.Printf("Warning: Failed to save translation for '%s': %v\n", word, err) + } } } // Create channels for parallel operations @@ -722,7 +726,9 @@ func (a *Application) generateMaterials(word string) { // Save phonetic info to disk using the pre-determined directory if phoneticInfo != "" && phoneticInfo != "Failed to fetch phonetic information" { phoneticFile := filepath.Join(cardDir, "phonetic.txt") - os.WriteFile(phoneticFile, []byte(phoneticInfo), 0644) + if err := os.WriteFile(phoneticFile, []byte(phoneticInfo), 0644); err != nil { + fmt.Printf("Warning: Failed to save phonetic info for '%s': %v\n", word, err) + } } // Update UI immediately with phonetic info if this is still the current word if phoneticInfo != "" && phoneticInfo != "Failed to fetch phonetic information" { @@ -2161,7 +2167,9 @@ func (a *Application) processWordJob(job *WordJob) { // Save phonetic info to disk immediately for this specific word if phoneticInfo != "" && phoneticInfo != "Failed to fetch phonetic information" { phoneticFile := filepath.Join(cardDir, "phonetic.txt") - os.WriteFile(phoneticFile, []byte(phoneticInfo), 0644) + if err := os.WriteFile(phoneticFile, []byte(phoneticInfo), 0644); err != nil { + fmt.Printf("Warning: Failed to save phonetic info for '%s': %v\n", job.Word, err) + } } // Update UI immediately with phonetic info if this is still the current job diff --git a/internal/gui/generator.go b/internal/gui/generator.go index 9c20e92..14f0f60 100644 --- a/internal/gui/generator.go +++ b/internal/gui/generator.go @@ -327,7 +327,9 @@ func (a *Application) generateImagesWithPrompt(ctx context.Context, word string, openaiClient.SetPromptCallback(func(prompt string) { // Save the prompt to disk immediately for this word promptFile := filepath.Join(cardDir, "image_prompt.txt") - os.WriteFile(promptFile, []byte(prompt), 0644) + if err := os.WriteFile(promptFile, []byte(prompt), 0644); err != nil { + fmt.Printf("Warning: Failed to save prompt for '%s': %v\n", word, err) + } // Only update UI if this word is still the current word a.mu.Lock() diff --git a/internal/gui/widgets.go b/internal/gui/widgets.go index 6e40391..aee6f13 100644 --- a/internal/gui/widgets.go +++ b/internal/gui/widgets.go @@ -81,7 +81,11 @@ func (d *ImageDisplay) SetImage(imagePath string) { d.imageLabel.SetText(fmt.Sprintf("Error loading image: %v", err)) return } - defer file.Close() + defer func() { + if closeErr := file.Close(); closeErr != nil { + fmt.Printf("Warning: failed to close image file %q: %v\n", imagePath, closeErr) + } + }() // Get file info to ensure it's fully written stat, err := file.Stat() @@ -141,7 +145,11 @@ func ResourceFromPath(path string) (fyne.Resource, error) { if err != nil { return nil, err } - defer file.Close() + defer func() { + if closeErr := file.Close(); closeErr != nil { + fmt.Printf("Warning: failed to close resource file %q: %v\n", path, closeErr) + } + }() data, err := os.ReadFile(path) if err != nil { -- cgit v1.2.3