From 4d61a6913c031e00d5339dfbe882f8ed0a02f5da Mon Sep 17 00:00:00 2001 From: lew Date: Wed, 11 Feb 2026 23:57:55 +0000 Subject: [PATCH] feat: exempt config/doctor from config errors, run doctor on failure When the config file is malformed, config and doctor commands now proceed with defaults (showing a warning). All other commands print the parse error and automatically run doctor to aid diagnosis. --- cmd/root.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 4f4a99f..cf75c2d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -39,8 +39,14 @@ var rootCmd = &cobra.Command{ func Execute() { if configErr != nil { - printError(fmt.Errorf("cannot load config: %v", configErr)) - os.Exit(1) + cmd, _, _ := rootCmd.Find(os.Args[1:]) + if configSafeCmd(cmd) { + warnf("config error: %v (using defaults)", configErr) + } else { + printError(fmt.Errorf("cannot load config: %v", configErr)) + runDoctor(os.Stderr) + os.Exit(1) + } } err := rootCmd.Execute() if err != nil { @@ -49,6 +55,16 @@ func Execute() { } } +// configSafeCmd reports whether cmd can run with a broken config. +func configSafeCmd(cmd *cobra.Command) bool { + for c := cmd; c != nil; c = c.Parent() { + if c == configCmd || c == doctorCmd { + return true + } + } + return false +} + func init() { rootCmd.AddGroup(&cobra.Group{ID: "keys", Title: "Key commands:"})