{"record":{"id":"7aef58c44976bd09","repo":"sipeed/picoclaw","slug":"failed-to-load-config-w-7aef58","errorCode":null,"errorMessage":"failed to load config: %w","messagePattern":"failed to load config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/picoclaw/internal/auth/weixin.go","lineNumber":95,"sourceCode":"\t}\n\n\tfmt.Println(\"✓ Config updated. Start the gateway with:\")\n\tfmt.Println()\n\tfmt.Println(\"  picoclaw gateway\")\n\tfmt.Println()\n\tfmt.Println(\"To restrict which WeChat users can send messages, add their user IDs\")\n\tfmt.Println(\"to channels.weixin.allow_from in your config.\")\n\n\treturn nil\n}\n\n// saveWeixinConfig patches channels.weixin in the config and saves it.\nfunc saveWeixinConfig(token, baseURL, proxy string) error {\n\tcfgPath := internal.GetConfigPath()\n\n\tcfg, err := config.LoadConfig(cfgPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load config: %w\", err)\n\t}\n\n\tbc := cfg.Channels.GetByType(config.ChannelWeixin)\n\tif bc == nil {\n\t\tbc = &config.Channel{Type: config.ChannelWeixin}\n\t\tcfg.Channels[config.ChannelWeixin] = bc\n\t}\n\tbc.Enabled = true\n\n\tif decoded, err := bc.GetDecoded(); err == nil && decoded != nil {\n\t\tif weixinCfg, ok := decoded.(*config.WeixinSettings); ok {\n\t\t\tweixinCfg.Token = *config.NewSecureString(token)\n\t\t\tconst defaultBase = \"https://ilinkai.weixin.qq.com/\"\n\t\t\tif baseURL != \"\" && baseURL != defaultBase {\n\t\t\t\tweixinCfg.BaseURL = baseURL\n\t\t\t}\n\t\t\tif proxy != \"\" {\n\t\t\t\tweixinCfg.Proxy = proxy","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/auth/weixin.go#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before: config.yaml has broken syntax\nchannels:\n  weixin { token: abc\n# after\nchannels:\n  weixin:\n    token: abc","handlingStrategy":"try-catch","validationCode":"bash -c 'picoclaw config path && picoclaw config validate' # run before `picoclaw auth weixin`; only proceed when both succeed","typeGuard":null,"tryCatchPattern":"if err := saveWeixinConfig(token, baseURL, proxy); err != nil {\n    var pe *fs.PathError\n    switch {\n    case errors.As(err, &pe):\n        // unreadable/missing config: fix path or permissions, then retry the flow\n    default:\n        // parse error: surface wrapped cause, point user at `picoclaw config path`\n    }\n    return fmt.Errorf(\"weixin setup: %w\", err)\n}","preventionTips":["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"],"tags":["config","cli","weixin","auth","persistence"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}