sipeed/picoclaw · error

failed to load config: %w

Error message

failed to load config: %w

What it means

picoclaw model add updated nothing yet — it failed while loading the existing config file (config.LoadConfig on the path from internal.GetConfigPath) before upserting the model entry. The wrapped error is the real cause: YAML/JSON syntax errors with a line/column, schema validation failures for unknown or ill-typed fields, or filesystem errors such as permission denied.

Source

Thrown at cmd/picoclaw/internal/model/add.go:163

				fmt.Fprintf(stdout, "Out of range. Enter 1-%d.\n", len(entries))
				continue
			}
			return entries[idx-1].ID, nil
		}
		for _, m := range entries {
			if m.ID == text {
				return m.ID, nil
			}
		}
		fmt.Fprintln(stdout, "Not a valid number or model id; try again.")
	}
}

func upsertModelDefault(apiBase, apiKey, alias, modelID string, stdout io.Writer) error {
	configPath := internal.GetConfigPath()
	cfg, err := config.LoadConfig(configPath)
	if err != nil {
		return fmt.Errorf("failed to load config: %w", err)
	}

	secureKeys := config.SimpleSecureStrings(apiKey)

	found := false
	for _, m := range cfg.ModelList {
		if m == nil {
			continue
		}
		if m.ModelName == alias {
			m.Model = modelID
			m.APIBase = apiBase
			m.APIKeys = secureKeys
			m.Enabled = true
			found = true
			break
		}
	}

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Read the wrapped message — it usually pinpoints the failing line/column or field
  2. Run a YAML/JSON linter on the reported config path
  3. Fix the field, restore a backup, or move the broken file aside and let picoclaw regenerate it, then re-add entries
  4. If the error is a read failure, fix ownership/permissions on the file

Example fix

# before (config file; tab indentation broke YAML)
model_list:
	- model_name: custom-prefer

# after
model_list:
  - model_name: custom-prefer
Defensive patterns

Strategy: validation

Validate before calling

configPath := internal.GetConfigPath()
if raw, err := os.ReadFile(configPath); err == nil {
  var probe map[string]any
  if json.Unmarshal(raw, &probe) != nil && yaml.Unmarshal(raw, &probe) != nil {
    return fmt.Errorf("config at %s is neither valid JSON nor YAML; fix before running", configPath)
  }
}

Type guard

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

Try / catch

if err := runAdd(opt); err != nil {
  if isConfigLoadError(err) {
    // show the config path and the wrapped parse error; suggest restoring a backup
  }
  return err
}

Prevention

When it happens

Trigger: Hand-editing the config and breaking indentation or value types; a config written by a newer picoclaw version containing fields this version's validator rejects; a truncated file after a crash mid-write; an unreadable file (wrong owner, restrictive mode).

Common situations: Editors inserting tabs into YAML; sharing one config across machines with different picoclaw versions; automation templates with syntax slips; interrupted saves.

Related errors


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