{"record":{"id":"07d99543141a2e6f","repo":"larksuite/cli","slug":"invalid-json-in-s-w-07d995","errorCode":null,"errorMessage":"invalid JSON in %s: %w","messagePattern":"invalid JSON in (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/binding/reader.go","lineNumber":22,"sourceCode":"package binding\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\n\t\"github.com/larksuite/cli/internal/vfs\"\n)\n\n// ReadOpenClawConfig reads and parses an openclaw.json file at the given path.\nfunc ReadOpenClawConfig(path string) (*OpenClawRoot, error) {\n\tdata, err := vfs.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, err // caller (bind.go) formats user-facing message with path context\n\t}\n\n\tvar root OpenClawRoot\n\tif err := json.Unmarshal(data, &root); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid JSON in %s: %w\", path, err)\n\t}\n\n\treturn &root, nil\n}\n","sourceCodeStart":4,"sourceCodeEnd":27,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/binding/reader.go#L4-L27","documentation":"ReadOpenClawConfig reads an openclaw.json file and unmarshals it into the OpenClawRoot struct (channels + secrets subtree). This error is thrown when the file exists and is readable but its bytes are not valid JSON (json.Unmarshal fails). The path is embedded in the message and the underlying json.SyntaxError/json.UnmarshalTypeError is wrapped via %w, so callers can inspect the cause for offset/type details.","triggerScenarios":"Calling ReadOpenClawConfig(path) where the file at path contains malformed JSON: truncated file, trailing commas, comments, single quotes, BOM, smart quotes from copy-paste, or an appSecret given as a non-string/non-object literal (the SecretInput.UnmarshalJSON error also surfaces here as an UnmarshalTypeError-style failure).","commonSituations":"A text editor or heredoc script wrote a partial/corrupt openclaw.json; a template placeholder like {{SECRET}} was never substituted; the file was hand-edited with comments or trailing commas that strict encoding/json rejects; a file-sync tool wrote a zero-byte or half-written file.","solutions":["Open the file named in the error and run it through a JSON linter (python3 -m json.tool <path>) to find the exact syntax error at the wrapped offset.","Remove JSON-illegal constructs: comments, trailing commas, single quotes, smart quotes; encoding/json is strict.","If a placeholder like {{...}} remains unsubstituted, supply the real value or an env template \"${VAR}\" instead.","Delete the corrupt file and re-run the tool that generates openclaw.json, or restore it from backup/version control.","Unwrap the cause in code (errors.As to *json.SyntaxError) to programmatically report line/column offsets."],"exampleFix":"// before (invalid: trailing comma)\n{ \"channels\": { \"feishu\": { \"appId\": \"cli_x\", \"appSecret\": \"s\" ,} } }\n// after\n{ \"channels\": { \"feishu\": { \"appId\": \"cli_x\", \"appSecret\": \"s\" } } }","handlingStrategy":"validation","validationCode":"func validateOpenClawJSON(path string) error {\n\tdata, err := os.ReadFile(path)\n\tif err != nil { return err }\n\tvar v any\n\tif err := json.Unmarshal(data, &v); err != nil {\n\t\tvar se *json.SyntaxError\n\t\tif errors.As(err, &se) {\n\t\t\tline := 1 + bytes.Count(data[:se.Offset], []byte(\"\\n\"))\n\t\t\treturn fmt.Errorf(\"%s: invalid JSON at line %d: %v\", path, line, se)\n\t\t}\n\t\treturn fmt.Errorf(\"%s: invalid JSON: %w\", path, err)\n\t}\n\treturn nil\n}","typeGuard":"func isOpenClawJSONValid(path string) bool {\n\tdata, err := os.ReadFile(path)\n\tif err != nil { return false }\n\tvar v any\n\treturn json.Unmarshal(data, &v) == nil\n}","tryCatchPattern":"root, err := binding.ReadOpenClawConfig(path)\nif err != nil {\n\tvar se *json.SyntaxError\n\tif errors.As(err, &se) {\n\t\tfmt.Fprintf(os.Stderr, \"fix JSON syntax at offset %d in %s: %v\\n\", se.Offset, path, se)\n\t}\n\treturn err\n}","preventionTips":["Run python3 -m json.tool openclaw.json (or a JSON linter in CI) after every hand edit or template render.","Never put comments or trailing commas in openclaw.json; encoding/json is strict.","Validate generated configs in CI immediately after template substitution.","Keep openclaw.json in version control so a corrupt edit is easy to revert."],"tags":["json","config","parsing"],"backgroundTag":"invalid-json-syntax","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}