sipeed/picoclaw · error
failed to load config: %w
Error message
failed to load config: %w
What it means
This error comes from the WeChat (weixin) channel setup flow. saveWeixinConfig re-reads the picoclaw config file with config.LoadConfig before it patches channels.weixin and saves the token/baseURL/proxy you just entered. The load failed, so nothing was written. The underlying cause is chained with %w and is almost always a missing, unreadable, or syntactically broken config file.
Source
Thrown at cmd/picoclaw/internal/auth/weixin.go:95
}
fmt.Println("✓ Config updated. Start the gateway with:")
fmt.Println()
fmt.Println(" picoclaw gateway")
fmt.Println()
fmt.Println("To restrict which WeChat users can send messages, add their user IDs")
fmt.Println("to channels.weixin.allow_from in your config.")
return nil
}
// saveWeixinConfig patches channels.weixin in the config and saves it.
func saveWeixinConfig(token, baseURL, proxy string) error {
cfgPath := internal.GetConfigPath()
cfg, err := config.LoadConfig(cfgPath)
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
bc := cfg.Channels.GetByType(config.ChannelWeixin)
if bc == nil {
bc = &config.Channel{Type: config.ChannelWeixin}
cfg.Channels[config.ChannelWeixin] = bc
}
bc.Enabled = true
if decoded, err := bc.GetDecoded(); err == nil && decoded != nil {
if weixinCfg, ok := decoded.(*config.WeixinSettings); ok {
weixinCfg.Token = *config.NewSecureString(token)
const defaultBase = "https://ilinkai.weixin.qq.com/"
if baseURL != "" && baseURL != defaultBase {
weixinCfg.BaseURL = baseURL
}
if proxy != "" {
weixinCfg.Proxy = proxyView on GitHub (pinned to 49183d7e8d)
Solutions
- Run `picoclaw config path` and open that file; fix the syntax error reported by the wrapped error
- Fix read/write permissions on the config file and its directory for the current user
- If the file is unrecoverable, move it aside and let picoclaw regenerate defaults, then re-enter secrets
- Re-run the weixin setup flow once the config loads cleanly
Example fix
# before: config.yaml has broken syntax
channels:
weixin { token: abc
# after
channels:
weixin:
token: abc Defensive patterns
Strategy: try-catch
Validate before calling
bash -c 'picoclaw config path && picoclaw config validate' # run before `picoclaw auth weixin`; only proceed when both succeed
Try / catch
if err := saveWeixinConfig(token, baseURL, proxy); err != nil {
var pe *fs.PathError
switch {
case errors.As(err, &pe):
// unreadable/missing config: fix path or permissions, then retry the flow
default:
// parse error: surface wrapped cause, point user at `picoclaw config path`
}
return fmt.Errorf("weixin setup: %w", err)
} Prevention
- Validate the config with `picoclaw config validate` before any auth/setup flow
- Never hand-edit the config while a picoclaw command is mid-write
- Keep a backup copy before manual edits so a broken file is a one-command restore
- Run picoclaw as the user who owns the config directory
When it happens
Trigger: Running `picoclaw auth weixin` (or any flow that calls saveWeixinConfig) when the file at internal.GetConfigPath() cannot be parsed (invalid YAML/JSON), cannot be read (permissions), or does not exist. The error appears right after the token prompts, before any write is attempted.
Common situations: Hand-edited config left with broken syntax; config directory owned by root or another user; PICOCLOW_HOME redirected to a missing path; a partially written config after a crashed process.
Related errors
- failed to load config: %w
- failed to save config: %w
- failed to load config: %w
- failed to save config: %w
- failed to create api client: %w
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/7aef58c44976bd09.
Report an issue: GitHub.