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)