{"record":{"id":"fe383d4010b27f2d","repo":"larksuite/cli","slug":"file-provider-json-parse-error-w","errorCode":null,"errorMessage":"file provider JSON parse error: %w","messagePattern":"file provider JSON parse error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/binding/secret_resolve_file.go","lineNumber":87,"sourceCode":"\tif mode == \"\" {\n\t\tmode = \"json\" // default mode per OpenClaw\n\t}\n\n\tswitch mode {\n\tcase \"singleValue\":\n\t\t// OpenClaw requires ref.id == SINGLE_VALUE_FILE_REF_ID for singleValue mode\n\t\tif ref.ID != SingleValueFileRefID {\n\t\t\treturn \"\", fmt.Errorf(\"singleValue file provider expects ref id %q, got %q\",\n\t\t\t\tSingleValueFileRefID, ref.ID)\n\t\t}\n\t\t// Entire file content is the secret; trim trailing newline\n\t\treturn strings.TrimRight(content, \"\\r\\n\"), nil\n\n\tcase \"json\":\n\t\t// Parse as JSON, then navigate via JSON Pointer (ref.ID)\n\t\tvar parsed interface{}\n\t\tif err := json.Unmarshal(data, &parsed); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"file provider JSON parse error: %w\", err)\n\t\t}\n\n\t\tvalue, err := ReadJSONPointer(parsed, ref.ID)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"file provider JSON Pointer %q: %w\", ref.ID, err)\n\t\t}\n\n\t\t// Value must be a string\n\t\tstrValue, ok := value.(string)\n\t\tif !ok {\n\t\t\treturn \"\", fmt.Errorf(\"file provider JSON Pointer %q resolved to non-string value\", ref.ID)\n\t\t}\n\t\treturn strValue, nil\n\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unsupported file provider mode %q\", mode)\n\t}\n}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/binding/secret_resolve_file.go#L69-L105","documentation":"In json mode the secret file must contain valid JSON so a JSON Pointer (ref.ID) can navigate it. json.Unmarshal failed, so the file is malformed JSON (or, commonly, a bare secret string without JSON braces). The parse error is wrapped for diagnosis.","triggerScenarios":"Calling resolveSecretRef with a {source:\"file\"} SecretRef in default (\"json\") mode where the file at Path is not parseable JSON — truncated file, trailing garbage, or a plain-text secret written without JSON encoding.","commonSituations":"A single-value secret was pasted raw into the file while the provider stayed in json mode; the file got truncated during a partial write or download; encoding issues (BOM) or comments added to the JSON.","solutions":["Validate the file: `jq . <path>` — fix syntax errors (trailing commas, comments, truncation).","If the file holds one bare secret, either wrap it in JSON (e.g. {\"value\":\"...\"} with id \"/value\") or set Mode to \"singleValue\".","Ensure the writer of the file serializes atomically (write temp file + rename) to avoid truncated reads."],"exampleFix":"// before (file content, json mode)\ns3cret-api-key\n// after\n{\"api_key\": \"s3cret-api-key\"}\n// with ref id \"/api_key\"","handlingStrategy":"validation","validationCode":"raw, err := os.ReadFile(os.ExpandEnv(pc.Path))\nif err == nil {\n    var probe any\n    if jerr := json.Unmarshal(raw, &probe); jerr != nil {\n        return fmt.Errorf(\"secret file %s is not valid JSON: %v\", pc.Path, jerr)\n    }\n}","typeGuard":"func isJSONObject(raw []byte) bool { var v any; return json.Unmarshal(raw, &v) == nil }","tryCatchPattern":"secret, err := resolveSecretRef(ctx, ref)\nif err != nil {\n    if strings.Contains(err.Error(), \"JSON parse error\") {\n        // jq . <path> to locate the syntax problem, or switch mode to singleValue\n    }\n    return err\n}","preventionTips":["Run `jq . <file>` after every manual edit of a json-mode secret file.","Write secret JSON atomically (temp file + rename) to avoid truncated reads.","Use singleValue mode for bare secrets instead of storing raw text in json mode.","Keep JSON free of comments and BOMs."],"tags":["secrets","file-provider","json","parse-error"],"backgroundTag":"invalid-json","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"}