{"record":{"id":"40134ebf075effe9","repo":"JuliusBrussee/caveman","slug":"not-valid-toon","errorCode":null,"errorMessage":"not valid TOON","messagePattern":"not valid TOON","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/cmd/caveman-engine/main.go","lineNumber":623,"sourceCode":"\n// toonEncodeBytes converts JSON to the lossless TOON subset. It fails closed:\n// any input that is not valid JSON, or whose shape is outside the proven\n// round-trip subset (deeply nested / non-uniform), returns an error rather than a\n// lossy approximation — so the caller keeps JSON instead of trusting bad TOON.\nfunc toonEncodeBytes(input []byte) ([]byte, error) {\n\tout, ok := compressors.NewTOON().Compress(input)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"not losslessly TOON-encodable (invalid JSON, or nested/non-uniform shape); keep JSON\")\n\t}\n\treturn out, nil\n}\n\n// toonDecodeBytes converts TOON back to compact JSON. Malformed TOON fails closed\n// with an error; it never emits partial or guessed JSON.\nfunc toonDecodeBytes(input []byte) ([]byte, error) {\n\tv, ok := compressors.DecodeTOON(input)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"not valid TOON\")\n\t}\n\tout, err := json.Marshal(v)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn out, nil\n}\n\nfunc runEvals(args []string) {\n\tif len(args) < 1 || args[0] != \"run\" {\n\t\tfatal(\"usage: caveman-engine evals run [--fixtures DIR]\")\n\t}\n\tfixtureDir := \"\"\n\tif len(args) == 3 && args[1] == \"--fixtures\" && args[2] != \"\" {\n\t\tfixtureDir = args[2]\n\t} else if len(args) != 1 {\n\t\tfatal(\"usage: caveman-engine evals run [--fixtures DIR]\")\n\t}","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/engine/cmd/caveman-engine/main.go#L605-L641","documentation":"toonDecodeBytes converts TOON back to compact JSON via compressors.DecodeTOON; if parsing fails (ok=false) it returns the fail-closed error \"not valid TOON\" instead of emitting partial or guessed JSON. The verb only round-trips inputs produced by the encoder.","triggerScenarios":"runTOON (decode direction) receives bytes that DecodeTOON cannot parse: truncated TOON output, manually edited TOON, or input that was never TOON (e.g. raw JSON or binary fed to the decode path).","commonSituations":"A pipeline stage truncated the TOON payload; a user hand-edited the TOON text; versions changed between encode and decode so the wire format differs; wrong verb used (encoding when decoding intended).","solutions":["Re-generate the TOON payload from the original JSON with the same engine version instead of editing/truncating it.","Confirm you are feeding TOON output (not raw JSON) to the decode verb.","Check both encode and decode run the same caveman-engine version to avoid format drift."],"exampleFix":"// before\ncaveman-engine toon --decode < edited_output.toon\n// after\ncaveman-engine toon < original.json > fresh.toon && caveman-engine toon --decode < fresh.toon","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := toonDecodeBytes(input)\nif err != nil {\n    log.Println(\"not valid TOON, re-encoding from source JSON\")\n    return reEncodeFromOriginal() // fallback path\n}","preventionTips":["Never hand-edit or truncate TOON output","Pin the same engine version on encode and decode sides","Store the source JSON alongside TOON for regeneration"],"tags":["toon","decode","parse-error"],"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"}