{"record":{"id":"169919c4077bb5ea","repo":"JuliusBrussee/caveman","slug":"array-not-closed","errorCode":null,"errorMessage":"array not closed","messagePattern":"array not closed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/compressors/toon_encode.go","lineNumber":175,"sourceCode":"\t\t\tif d, ok := end.(json.Delim); !ok || d != '}' {\n\t\t\t\treturn toonValue{}, fmt.Errorf(\"object not closed\")\n\t\t\t}\n\t\t\treturn toonValue{kind: toonObject, obj: fields}, nil\n\t\tcase '[':\n\t\t\tvar arr []toonValue\n\t\t\tfor dec.More() {\n\t\t\t\tval, err := readJSONTOONValue(dec)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn toonValue{}, err\n\t\t\t\t}\n\t\t\t\tarr = append(arr, val)\n\t\t\t}\n\t\t\tend, err := dec.Token()\n\t\t\tif err != nil {\n\t\t\t\treturn toonValue{}, err\n\t\t\t}\n\t\t\tif d, ok := end.(json.Delim); !ok || d != ']' {\n\t\t\t\treturn toonValue{}, fmt.Errorf(\"array not closed\")\n\t\t\t}\n\t\t\treturn toonValue{kind: toonArray, arr: arr}, nil\n\t\tdefault:\n\t\t\treturn toonValue{}, fmt.Errorf(\"unexpected delimiter %q\", t)\n\t\t}\n\tcase nil:\n\t\treturn toonValue{kind: toonNull}, nil\n\tcase bool:\n\t\treturn toonValue{kind: toonBool, b: t}, nil\n\tcase json.Number:\n\t\treturn toonValue{kind: toonNumber, s: t.String()}, nil\n\tcase string:\n\t\treturn toonValue{kind: toonString, s: t}, nil\n\tdefault:\n\t\treturn toonValue{}, fmt.Errorf(\"unsupported token %T\", tok)\n\t}\n}\n","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/engine/compressors/toon_encode.go#L157-L193","documentation":"readJSONTOONValue decodes a JSON array into a toonValue during TOON encoding. After consuming all element tokens it reads the next token and requires the ']' delimiter; if the token is not ']' (e.g. '}' or a value token), it means the JSON is malformed or truncated and the array was never closed, so encoding aborts with this error.","triggerScenarios":"Calling parseJSONTOON on input where an array opened with '[' is never terminated with ']' — e.g. invalid JSON like \"[1,2\" or nested structure where a '}' or value token appears where ']' is required.","commonSituations":"Passing truncated JSON from a network stream or partial file read to the TOON encoder; hand-built JSON strings with mismatched brackets; upstream tools emitting broken JSON that bypassed prior validation.","solutions":["Validate the JSON with encoding/json (json.Valid or a decoder round-trip) before passing it to parseJSONTOON.","Check the source of the data for truncation — incomplete file reads or cut-off HTTP bodies.","Fix bracket balance in hand-authored JSON; run it through a linter/formatter."],"exampleFix":"// before\nencodeToonFromBytes(truncatedBody)\n// after\nif !json.Valid(truncatedBody) {\n    return fmt.Errorf(\"invalid JSON input: %d bytes\", len(truncatedBody))\n}\nencodeToonFromBytes(truncatedBody)","handlingStrategy":"validation","validationCode":"if !json.Valid(input) {\n    return fmt.Errorf(\"refusing TOON encode: input is not valid JSON\")\n}","typeGuard":null,"tryCatchPattern":"v, err := parseJSONTOON(input)\nif err != nil {\n    if strings.Contains(err.Error(), \"array not closed\") {\n        // log input offset and reject or re-fetch the payload\n    }\n    return err\n}","preventionTips":["Run json.Valid (or a decoder round-trip) on all external JSON before TOON encoding.","Check for truncation when reading JSON from streams or files (compare expected vs actual length).","Use a JSON formatter/linter in CI for any hand-authored fixtures."],"tags":["json","parser","toon","encoding"],"backgroundTag":"json-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}