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) {
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,12 +138,14 @@ func runDoctor(w io.Writer) bool {
}
}
// 7. Non-default config values
// 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
store := &Store{}

View file

@ -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)