{"record":{"id":"78a5435f1e6532c3","repo":"JuliusBrussee/caveman","slug":"unexpected-delimiter-q","errorCode":null,"errorMessage":"unexpected delimiter %q","messagePattern":"unexpected delimiter %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/compressors/toon_encode.go","lineNumber":179,"sourceCode":"\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\nfunc writeTOONValue(b *strings.Builder, v toonValue, name string, indent int, opt EncodeOptions) bool {\n\tswitch v.kind {\n\tcase toonObject:\n\t\tif name == \"\" {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/engine/compressors/toon_encode.go#L161-L197","documentation":"readJSONTOONValue hits its default case when the json.Decoder yields a delimiter token that the current parse context does not allow — for example a '{' or '}' appearing where a value or a specific closing bracket is expected. The library cannot map that delimiter to any toonValue production, so it reports the offending delimiter with %q.","triggerScenarios":"Input JSON with structurally misplaced delimiters, e.g. \"[{}]\" handled by a scalar branch, \"{\" closed by ']'{, or a bare '}' at the top level of a value being parsed by parseJSONTOON.","commonSituations":"Concatenating JSON fragments incorrectly; string templates that inject a closing brace too early; encoding a value that is a bare delimiter-bearing JSON document instead of a value.","solutions":["Run json.Valid on the input before parseJSONTOON to reject structurally broken JSON early.","Print the offending input around the failure position (use json.Decoder.InputOffset) to locate the misplaced delimiter.","Fix the JSON producer so delimiters are balanced and correctly nested."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"dec := json.NewDecoder(bytes.NewReader(input))\nif err := dec.Decode(&json.RawMessage{}); err != nil {\n    return fmt.Errorf(\"invalid JSON at offset %d: %w\", dec.InputOffset(), err)\n}","typeGuard":null,"tryCatchPattern":"v, err := parseJSONTOON(input)\nif err != nil {\n    var off int64\n    // use a pre-pass decoder's InputOffset to locate the misplaced delimiter\n    _ = off\n    return fmt.Errorf(\"toon encode failed: %w\", err)\n}","preventionTips":["Validate JSON structure before encoding; reject documents with mismatched delimiters early.","Avoid concatenating JSON fragments manually — build payloads with encoding/json marshaling.","Log dec.InputOffset() on failure to pinpoint the bad delimiter."],"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"}