From 413be07a1dda2e1111d1bbfdd5ae4f2a8d2c8fbe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Jun 2026 12:17:56 +0000 Subject: [PATCH 1/7] Initial plan From 555121bfe75e4abacc8d207dd268bea82435f93c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Jun 2026 12:20:06 +0000 Subject: [PATCH 2/7] Apply remaining changes --- cmd/root.go | 15 ++++++++++++--- internal/config/config.go | 22 +++++++++++++++------- internal/config/config_test.go | 19 ++++++++++++++++--- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 0d92fcf..87303ff 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,7 +95,10 @@ func runDiff(cmd *cobra.Command, args []string) error { } } - cfg := config.Load() + cfg, err := config.Load() + if err != nil { + return err + } t := resolveTheme(cfg) styles := ui.NewStyles(t) @@ -149,7 +152,10 @@ func runCommit(cmd *cobra.Command, args []string) error { return nil } - cfg := config.Load() + cfg, err := config.Load() + if err != nil { + return err + } t := resolveTheme(cfg) styles := ui.NewStyles(t) @@ -170,7 +176,10 @@ func runLog(cmd *cobra.Command, args []string) error { return nil } - cfg := config.Load() + cfg, err := config.Load() + if err != nil { + return err + } t := resolveTheme(cfg) styles := ui.NewStyles(t) diff --git a/internal/config/config.go b/internal/config/config.go index fddea70..1e8146d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,8 @@ package config import ( "encoding/json" + "errors" + "fmt" "os" "path/filepath" ) @@ -26,23 +28,29 @@ func Default() Config { // Load reads config from ~/.config/differ/config.json. // Returns defaults if file doesn't exist. -func Load() Config { +func Load() (Config, error) { path, err := configPath() if err != nil { - return Default() + return Default(), fmt.Errorf("could not resolve config path: %w", err) } return LoadFrom(path) } -// LoadFrom reads config from the given path. Returns defaults on error. -func LoadFrom(path string) Config { +// LoadFrom reads config from the given path. +// Returns defaults without error if file doesn't exist. +func LoadFrom(path string) (Config, error) { cfg := Default() data, err := os.ReadFile(path) if err != nil { - return cfg + if errors.Is(err, os.ErrNotExist) { + return cfg, nil + } + return cfg, fmt.Errorf("could not read config file %q: %w", path, err) } - _ = json.Unmarshal(data, &cfg) - return cfg + if err := json.Unmarshal(data, &cfg); err != nil { + return cfg, fmt.Errorf("invalid config file %q: %w; fix the JSON or remove the file to use defaults", path, err) + } + return cfg, nil } // Save writes config to ~/.config/differ/config.json. diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 3cfa8af..7f26e1f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -3,6 +3,7 @@ package config import ( "os" "path/filepath" + "strings" "testing" ) @@ -38,7 +39,10 @@ func TestSaveAndLoad(t *testing.T) { t.Fatalf("SaveTo: %v", err) } - got := LoadFrom(path) + got, err := LoadFrom(path) + if err != nil { + t.Fatalf("LoadFrom: %v", err) + } if got.Theme != "light" { t.Errorf("Theme=%q, want light", got.Theme) } @@ -56,7 +60,10 @@ func TestSaveAndLoad(t *testing.T) { func TestLoad_NoFile(t *testing.T) { t.Parallel() path := filepath.Join(t.TempDir(), "nonexistent.json") - cfg := LoadFrom(path) + cfg, err := LoadFrom(path) + if err != nil { + t.Fatalf("LoadFrom missing file: %v", err) + } if cfg.Theme != "dark" || cfg.TabWidth != 4 { t.Error("missing file should return defaults") } @@ -69,7 +76,13 @@ func TestLoad_InvalidJSON(t *testing.T) { t.Fatal(err) } - cfg := LoadFrom(path) + cfg, err := LoadFrom(path) + if err == nil { + t.Fatal("LoadFrom should return an error for invalid JSON") + } + if !strings.HasPrefix(err.Error(), "invalid config file") { + t.Fatalf("LoadFrom error = %q, want invalid config prefix", err.Error()) + } if cfg.Theme != "dark" || cfg.TabWidth != 4 { t.Error("invalid JSON should return defaults") } From 82d5410f0d40e897cc2e3637b6f1f84e95f3e0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Smr=C4=8Dka?= <55892155+JanSmrcka@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:17:03 +0200 Subject: [PATCH 3/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- cmd/root.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 87303ff..405c4c8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -176,10 +176,10 @@ func runLog(cmd *cobra.Command, args []string) error { return nil } - cfg, err := config.Load() - if err != nil { - return err - } +cfg, err := config.Load() +if err != nil { + return fmt.Errorf("config: %w", err) +} t := resolveTheme(cfg) styles := ui.NewStyles(t) From bf661998bffb3ce527610e1ede0e989d54ba011e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Smr=C4=8Dka?= <55892155+JanSmrcka@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:17:10 +0200 Subject: [PATCH 4/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- cmd/root.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 405c4c8..71d1a8f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -152,10 +152,10 @@ func runCommit(cmd *cobra.Command, args []string) error { return nil } - cfg, err := config.Load() - if err != nil { - return err - } +cfg, err := config.Load() +if err != nil { + return fmt.Errorf("config: %w", err) +} t := resolveTheme(cfg) styles := ui.NewStyles(t) From 7bfa617975f142f34739933e75500c342d757195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Smr=C4=8Dka?= <55892155+JanSmrcka@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:17:17 +0200 Subject: [PATCH 5/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- cmd/root.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 71d1a8f..7d2ed44 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -95,10 +95,10 @@ func runDiff(cmd *cobra.Command, args []string) error { } } - cfg, err := config.Load() - if err != nil { - return err - } +cfg, err := config.Load() +if err != nil { + return fmt.Errorf("config: %w", err) +} t := resolveTheme(cfg) styles := ui.NewStyles(t) From 2310c54d0ad6193a82e0d5833e583f6e4268605f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Smr=C4=8Dka?= <55892155+JanSmrcka@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:17:25 +0200 Subject: [PATCH 6/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 1e8146d..18c4fe1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -37,7 +37,7 @@ func Load() (Config, error) { } // LoadFrom reads config from the given path. -// Returns defaults without error if file doesn't exist. +// Returns defaults and a nil error if the file doesn't exist; otherwise returns defaults plus an error on failures (e.g., read/parse errors). func LoadFrom(path string) (Config, error) { cfg := Default() data, err := os.ReadFile(path) From 9ccd5521514b7b602d971ea9d0778b277b33f587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Smr=C4=8Dka?= <55892155+JanSmrcka@users.noreply.github.com> Date: Wed, 8 Jul 2026 09:17:33 +0200 Subject: [PATCH 7/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 18c4fe1..f382782 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,7 +27,7 @@ func Default() Config { } // Load reads config from ~/.config/differ/config.json. -// Returns defaults if file doesn't exist. +// Returns defaults and a nil error if the file doesn't exist; otherwise returns defaults plus an error on failures. func Load() (Config, error) { path, err := configPath() if err != nil {