{"record":{"id":"3a18da070af9b506","repo":"sipeed/picoclaw","slug":"failed-to-load-config-w","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/wecom.go","lineNumber":116,"sourceCode":"\treturn authWeComCmdWithScanner(context.Background(), os.Stdout, timeout, scanWeComQRCodeInteractive)\n}\n\nfunc authWeComCmdWithScanner(\n\tctx context.Context,\n\twriter io.Writer,\n\ttimeout time.Duration,\n\tscanner wecomQRScanner,\n) error {\n\tif scanner == nil {\n\t\treturn fmt.Errorf(\"wecom QR scanner is nil\")\n\t}\n\tif writer == nil {\n\t\twriter = os.Stdout\n\t}\n\n\tcfg, err := internal.LoadConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to load config: %w\", err)\n\t}\n\n\topts := defaultWeComQRFlowOptions(timeout)\n\topts.Writer = writer\n\n\tbotInfo, err := scanner(ctx, opts)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tapplyWeComAuthResult(cfg, botInfo)\n\n\tif saveErr := config.SaveConfig(internal.GetConfigPath(), cfg); saveErr != nil {\n\t\treturn fmt.Errorf(\"failed to save config: %w\", saveErr)\n\t}\n\n\tfmt.Fprintln(writer)\n\tfmt.Fprintln(writer, \"WeCom connected.\")","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/auth/wecom.go#L98-L134","documentation":"internal.LoadConfig (cmd/picoclaw/internal/helpers.go:27) failed while preparing the WeCom login flow. LoadConfig reads config.json from $PICOCLAW_CONFIG_PATH or ~/.picoclaw/config.json; a missing file returns defaults without error, so this error means the file exists but is unreadable, contains malformed JSON (reported via wrapJSONError diagnostics), or a config schema migration (V0→V1→V2→V3) failed.","triggerScenarios":"Hand-edited config.json with invalid JSON; config file with wrong permissions or an unreadable path; a legacy version-0 config whose migration fails; PICOCLAW_CONFIG_PATH pointing at a directory or corrupt file.","commonSituations":"User manually edits ~/.picoclaw/config.json and leaves a trailing comma; an older picoclaw version wrote a schema the current migration cannot handle; file owned by root after running with sudo.","solutions":["Run the same load outside the flow (e.g. a status command) to see the detailed diagnostic line logged by LoadConfig, which names the exact JSON offset","Validate config.json syntax with a JSON linter (e.g. jq . ~/.picoclaw/config.json)","Fix permissions: chown the file to your user and ensure it is readable/writable (0600)","If the file is a legacy version that fails migration, back it up and let picoclaw regenerate a default config, then re-add settings","Check PICOCLAW_CONFIG_PATH / PICOCLAW_HOME env vars point at the intended file"],"exampleFix":"// before\ncfg, err := internal.LoadConfig()\nif err != nil {\n\treturn fmt.Errorf(\"failed to load config: %w\", err)\n}\n\n// after: tell the user exactly which file failed\ncfg, err := internal.LoadConfig()\nif err != nil {\n\treturn fmt.Errorf(\"failed to load config %s: %w\\nvalidate with: jq . %s\", internal.GetConfigPath(), err, internal.GetConfigPath())\n}","handlingStrategy":"validation","validationCode":"// Fail fast with a clear message before starting an interactive flow\npath := internal.GetConfigPath()\nif data, err := os.ReadFile(path); err == nil {\n\tif !json.Valid(data) {\n\t\treturn fmt.Errorf(\"%s is not valid JSON — fix it before continuing\", path)\n\t}\n}","typeGuard":"func isConfigSyntaxError(err error) bool {\n\tvar syn *json.SyntaxError\n\treturn errors.As(err, &syn)\n}","tryCatchPattern":"cfg, err := internal.LoadConfig()\nif err != nil {\n\tif isConfigSyntaxError(err) {\n\t\treturn fmt.Errorf(\"config file has a JSON syntax error at offset — run: jq . %s\", internal.GetConfigPath())\n\t}\n\treturn fmt.Errorf(\"failed to load config: %w\", err)\n}","preventionTips":["Validate config.json with jq after every manual edit","Keep config files user-owned; avoid running picoclaw under sudo","Back up config.json before schema-migrating versions"],"tags":["go","config","json","wecom"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}