sipeed/picoclaw · error

failed to load config: %w

Error message

failed to load config: %w

What it means

picoclaw model (any subcommand, including showing the current default) failed while loading the config file via config.LoadConfig on internal.GetConfigPath. The wrapped error is the real cause: YAML/JSON parse errors with line/column, schema validation failures for unknown or ill-typed fields, or read errors such as permission denied.

Source

Thrown at cmd/picoclaw/internal/model/command.go:45

  picoclaw model add --help

Examples:
  picoclaw model                    # Show current default model
  picoclaw model gpt-5.2           # Set gpt-5.2 as default
  picoclaw model claude-sonnet-4.6 # Set claude-sonnet-4.6 as default
  picoclaw model local-model       # Set local VLLM server as default
  picoclaw model add -b URL -k KEY # Add a model from a custom endpoint

Note: 'local-model' is a special value for using a local VLLM server
(running at localhost:8000 by default) which does not require an API key.`,
		Args: cobra.MaximumNArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			configPath := internal.GetConfigPath()

			// Load current config
			cfg, err := config.LoadConfig(configPath)
			if err != nil {
				return fmt.Errorf("failed to load config: %w", err)
			}

			if len(args) == 0 {
				// Show current default model
				showCurrentModel(cfg)
				return nil
			}

			// Set new default model
			modelName := args[0]
			return setDefaultModel(configPath, cfg, modelName)
		},
	}

	cmd.AddCommand(newAddCommand())

	return cmd
}

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Read the wrapped message for the exact line/column or field that failed
  2. Validate the file with a YAML/JSON linter
  3. Fix the field, restore a backup, or move the file aside and regenerate the config
  4. Check file permissions if the error is a read failure

Example fix

# before (config file; wrong value type)
agents:
  defaults:
    model_name: [custom-prefer]

# after
agents:
  defaults:
    model_name: custom-prefer
Defensive patterns

Strategy: validation

Validate before calling

configPath := internal.GetConfigPath()
if _, err := config.LoadConfig(configPath); err != nil {
  return fmt.Errorf("refusing to run with broken config at %s: %w", configPath, err)
}

Type guard

func isConfigLoadError(err error) bool {
  return err != nil && strings.Contains(err.Error(), "failed to load config")
}

Try / catch

if err := modelCmd.Execute(); err != nil {
  if isConfigLoadError(err) {
    // print the wrapped line/column info and offer to open the config
  }
  return err
}

Prevention

When it happens

Trigger: Config broken by a manual edit (tabs in YAML, wrong types); fields written by a newer picoclaw version failing this version's validation; a truncated config after an interrupted write; an unreadable file.

Common situations: Hand-edited configs; version mismatches across machines or after downgrades; config templating in automation; crash-during-save leftovers.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/6272cb3f31802dd0. Report an issue: GitHub.