JuliusBrussee/caveman · error
cacheengine: invalid array close
Error message
cacheengine: invalid array close
What it means
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.
Source
Thrown at cacheengine/native.go:527
return false, errors.New("cacheengine: invalid object close")
}
return found, nil
case '[':
if root {
return false, errors.New("cacheengine: request root must be object")
}
found := false
path = append(path, "*")
for decoder.More() {
childFound, err := inspectUniqueJSONValue(decoder, false, depth+1, provider, path)
if err != nil {
return false, err
}
found = found || childFound
}
closing, err := decoder.Token()
if err != nil || closing != json.Delim(']') {
return false, errors.New("cacheengine: invalid array close")
}
return found, nil
default:
return false, errors.New("cacheengine: unexpected delimiter")
}
}
View on GitHub (pinned to 27d5a3981a)
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
Example fix
// before
body := raw[:len(raw)-9] // naive tail strip, can cut the closing ']'
// after
var req map[string]any
if err := json.Unmarshal(raw, &req); err != nil { return err }
body, _ := json.Marshal(req) Defensive patterns
Strategy: validation
Validate before calling
if !json.Valid(body) { return errors.New("invalid JSON body") } Type guard
// n/a
Prevention
- Re-marshal edited bodies instead of string surgery
- Verify content-length after any body rewrite
When it happens
Trigger: 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.
Common situations: Body truncation by a size-limited proxy; string-surgery on serialized JSON that removes a closing bracket; fixtures with mismatched brackets from templating.
Related errors
- cacheengine: invalid object close
- cacheengine: request root must be object
- cacheengine: duplicate or invalid object key
- cacheengine: JSON nesting limit exceeded
- cacheengine: unexpected delimiter
AI-assisted analysis of JuliusBrussee/caveman@27d5a3981a (2026-08-15).
Data as JSON: /api/errors/161d10df4109d361.
Report an issue: GitHub.