{"record":{"id":"9f0320eed3dede7c","repo":"sipeed/picoclaw","slug":"failed-to-load-config-w-9f0320","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/mcp/helpers.go","lineNumber":101,"sourceCode":"              }\n            }\n          },\n          \"required\": [\"enabled\"],\n          \"additionalProperties\": true\n        }\n      },\n      \"required\": [\"mcp\"],\n      \"additionalProperties\": true\n    }\n  },\n  \"required\": [\"tools\"],\n  \"additionalProperties\": true\n}`\n\nfunc loadConfig() (*config.Config, error) {\n\tcfg, err := config.LoadConfig(internal.GetConfigPath())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to load config: %w\", err)\n\t}\n\treturn cfg, nil\n}\n\nfunc saveValidatedConfig(cfg *config.Config) error {\n\tif cfg == nil {\n\t\treturn fmt.Errorf(\"config is nil\")\n\t}\n\n\tnormalizedCfg := normalizedConfigForSave(cfg)\n\n\tdata, err := json.Marshal(normalizedCfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to serialize config: %w\", err)\n\t}\n\n\tif err := validateConfigDocument(data); err != nil {\n\t\treturn err","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/mcp/helpers.go#L83-L119","documentation":"loadConfig (helpers.go:98-104) wraps config.LoadConfig(internal.GetConfigPath()); it fails when the config file is missing at the expected path, unreadable, or unparseable. Every mcp subcommand that touches persisted state (add, edit, list, remove) starts here, so this error surfaces before any subcommand logic runs.","triggerScenarios":"Config file deleted/renamed; JSON syntax error from a previous manual edit; unreadable permissions; a config-path override pointing at a nonexistent file.","commonSituations":"Hand-editing and leaving a trailing comma; dotfile sync between machines with different XDG paths; another tool rewriting the config and corrupting it.","solutions":["Locate the expected file via the CLI's config path and lint it as JSON (e.g. jq . file >/dev/null) to find the syntax error","Restore from a backup, or move the broken file aside so picoclaw recreates a default on next run","Check read permission on the file and every parent directory"],"exampleFix":"# before: config has a trailing comma\n# after: valid JSON\n# { \"tools\": { \"mcp\": { \"enabled\": true, \"servers\": {} } } }","handlingStrategy":"try-catch","validationCode":"cfgPath=$(picoclaw config path 2>/dev/null || echo \"$HOME/.config/picoclaw/config.json\")\njq . \"$cfgPath\" >/dev/null || { echo \"config is not valid JSON\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"failed to load config\") {\n\t\t// err wraps the underlying *fs.PathError / json syntax error via %w\n\t\tfmt.Fprintf(os.Stderr, \"config problem: %v\\n\", errors.Unwrap(err))\n\t}\n}","preventionTips":["Keep the config under version control or a backup before manual edits","Validate with jq after every hand edit","Prefer `picoclaw mcp add` over hand-editing to stay on the validated path"],"tags":["config","cli","json","filesystem"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}