{"record":{"id":"161d10df4109d361","repo":"JuliusBrussee/caveman","slug":"cacheengine-invalid-array-close","errorCode":null,"errorMessage":"cacheengine: invalid array close","messagePattern":"cacheengine: invalid array close","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/native.go","lineNumber":527,"sourceCode":"\t\t\treturn false, errors.New(\"cacheengine: invalid object close\")\n\t\t}\n\t\treturn found, nil\n\tcase '[':\n\t\tif root {\n\t\t\treturn false, errors.New(\"cacheengine: request root must be object\")\n\t\t}\n\t\tfound := false\n\t\tpath = append(path, \"*\")\n\t\tfor decoder.More() {\n\t\t\tchildFound, err := inspectUniqueJSONValue(decoder, false, depth+1, provider, path)\n\t\t\tif err != nil {\n\t\t\t\treturn false, err\n\t\t\t}\n\t\t\tfound = found || childFound\n\t\t}\n\t\tclosing, err := decoder.Token()\n\t\tif err != nil || closing != json.Delim(']') {\n\t\t\treturn false, errors.New(\"cacheengine: invalid array close\")\n\t\t}\n\t\treturn found, nil\n\tdefault:\n\t\treturn false, errors.New(\"cacheengine: unexpected delimiter\")\n\t}\n}\n","sourceCodeStart":509,"sourceCodeEnd":534,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/native.go#L509-L534","documentation":"Thrown by inspectUniqueJSONValue when, after walking all elements of an array, the closing token is not ']'. Like the object-close error, a correct decoder stream cannot reach this with valid JSON; it signals truncated or malformed array structure in the body.","triggerScenarios":"A body containing an unterminated or wrongly-closed array, e.g. '{\"messages\":[{\"role\":\"user\"}' — combined with streaming-decoder behavior; practically seen with truncated bodies or byte-level body edits.","commonSituations":"Body truncation by a size-limited proxy; string-surgery on serialized JSON that removes a closing bracket; fixtures with mismatched brackets from templating.","solutions":["Run json.Valid on the body before the engine call and reject early with a clear error","Re-marshal instead of byte-editing JSON bodies","Verify content-length/body-size accounting in any middleware that rewrites bodies"],"exampleFix":"// before\nbody := raw[:len(raw)-9] // naive tail strip, can cut the closing ']'\n\n// after\nvar req map[string]any\nif err := json.Unmarshal(raw, &req); err != nil { return err }\nbody, _ := json.Marshal(req)","handlingStrategy":"validation","validationCode":"if !json.Valid(body) { return errors.New(\"invalid JSON body\") }","typeGuard":"// n/a","tryCatchPattern":null,"preventionTips":["Re-marshal edited bodies instead of string surgery","Verify content-length after any body rewrite"],"tags":["cacheengine","json","malformed","protocol","go"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}