fix(doctor): report config parse errors, remove redundant error in Execute

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.
This commit is contained in:
Lewis Wynne 2026-02-12 00:07:14 +00:00
parent b4c89e7d90
commit 6ad6876051
2 changed files with 11 additions and 8 deletions

View file

@ -115,6 +115,10 @@ func runDoctor(w io.Writer) bool {
if _, statErr := os.Stat(cfgPath); statErr != nil && !os.IsNotExist(statErr) { if _, statErr := os.Stat(cfgPath); statErr != nil && !os.IsNotExist(statErr) {
issues = append(issues, fmt.Sprintf("Config file unreadable: %s", cfgPath)) 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{ if unexpectedFiles(cfgDir, map[string]bool{
"config.toml": true, "config.toml": true,
"identity.txt": true, "identity.txt": true,
@ -134,11 +138,13 @@ func runDoctor(w io.Writer) bool {
} }
} }
// 7. Non-default config values // 7. Non-default config values (skip if config failed to parse)
defaults := defaultConfig() if configErr == nil {
if diffs := configDiffStrings(configFields(&config, &defaults)); len(diffs) > 0 { defaults := defaultConfig()
emit("ok", "Non-default config:") if diffs := configDiffStrings(configFields(&config, &defaults)); len(diffs) > 0 {
tree(diffs) emit("ok", "Non-default config:")
tree(diffs)
}
} }
// 8. Data directory // 8. Data directory

View file

@ -23,7 +23,6 @@ THE SOFTWARE.
package cmd package cmd
import ( import (
"fmt"
"os" "os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -41,8 +40,6 @@ func Execute() {
if configErr != nil { if configErr != nil {
cmd, _, _ := rootCmd.Find(os.Args[1:]) cmd, _, _ := rootCmd.Find(os.Args[1:])
if !configSafeCmd(cmd) { if !configSafeCmd(cmd) {
printError(fmt.Errorf("cannot load config: %v", configErr))
fmt.Fprintln(os.Stderr)
infof("Running pda! doctor") infof("Running pda! doctor")
runDoctor(os.Stderr) runDoctor(os.Stderr)
os.Exit(1) os.Exit(1)