From 6ad6876051cf69714f035f31be9736334d92bf38 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 12 Feb 2026 00:07:14 +0000 Subject: [PATCH] fix(doctor): report config parse errors, remove redundant error in Execute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Doctor now checks configErr and emits a FAIL with the parse error and fix hint. Execute() no longer prints a separate error before running doctor — the doctor output is self-contained. --- cmd/doctor.go | 16 +++++++++++----- cmd/root.go | 3 --- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/doctor.go b/cmd/doctor.go index 394e43f..f14373b 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -115,6 +115,10 @@ func runDoctor(w io.Writer) bool { if _, statErr := os.Stat(cfgPath); statErr != nil && !os.IsNotExist(statErr) { issues = append(issues, fmt.Sprintf("Config file unreadable: %s", cfgPath)) } + if configErr != nil { + issues = append(issues, fmt.Sprintf("Parse error: %v", configErr)) + issues = append(issues, "Fix with 'pda config edit' or 'pda config init --new'") + } if unexpectedFiles(cfgDir, map[string]bool{ "config.toml": true, "identity.txt": true, @@ -134,11 +138,13 @@ func runDoctor(w io.Writer) bool { } } - // 7. Non-default config values - defaults := defaultConfig() - if diffs := configDiffStrings(configFields(&config, &defaults)); len(diffs) > 0 { - emit("ok", "Non-default config:") - tree(diffs) + // 7. Non-default config values (skip if config failed to parse) + if configErr == nil { + defaults := defaultConfig() + if diffs := configDiffStrings(configFields(&config, &defaults)); len(diffs) > 0 { + emit("ok", "Non-default config:") + tree(diffs) + } } // 8. Data directory diff --git a/cmd/root.go b/cmd/root.go index c6de8f8..e718397 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,7 +23,6 @@ THE SOFTWARE. package cmd import ( - "fmt" "os" "github.com/spf13/cobra" @@ -41,8 +40,6 @@ func Execute() { if configErr != nil { cmd, _, _ := rootCmd.Find(os.Args[1:]) if !configSafeCmd(cmd) { - printError(fmt.Errorf("cannot load config: %v", configErr)) - fmt.Fprintln(os.Stderr) infof("Running pda! doctor") runDoctor(os.Stderr) os.Exit(1)