JuliusBrussee/caveman · error
not valid TOON
Error message
not valid TOON
What it means
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.
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.
Example fix
// before caveman-engine toon --decode < edited_output.toon // after caveman-engine toon < original.json > fresh.toon && caveman-engine toon --decode < fresh.toon
Defensive patterns
Strategy: fallback
Try / catch
out, err := toonDecodeBytes(input)
if err != nil {
log.Println("not valid TOON, re-encoding from source JSON")
return reEncodeFromOriginal() // fallback path
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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).
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- object not closed
- array not closed
- cannot preserve opencode inline configuration; launching…
- duplicate object key
- eval evidence line is not valid JSON
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/40134ebf075effe9.
Report an issue: GitHub.
Appendix: source
Thrown at engine/cmd/caveman-engine/main.go:623
// toonEncodeBytes converts JSON to the lossless TOON subset. It fails closed:
// any input that is not valid JSON, or whose shape is outside the proven
// round-trip subset (deeply nested / non-uniform), returns an error rather than a
// lossy approximation — so the caller keeps JSON instead of trusting bad TOON.
func toonEncodeBytes(input []byte) ([]byte, error) {
out, ok := compressors.NewTOON().Compress(input)
if !ok {
return nil, fmt.Errorf("not losslessly TOON-encodable (invalid JSON, or nested/non-uniform shape); keep JSON")
}
return out, nil
}
// toonDecodeBytes converts TOON back to compact JSON. Malformed TOON fails closed
// with an error; it never emits partial or guessed JSON.
func toonDecodeBytes(input []byte) ([]byte, error) {
v, ok := compressors.DecodeTOON(input)
if !ok {
return nil, fmt.Errorf("not valid TOON")
}
out, err := json.Marshal(v)
if err != nil {
return nil, err
}
return out, nil
}
func runEvals(args []string) {
if len(args) < 1 || args[0] != "run" {
fatal("usage: caveman-engine evals run [--fixtures DIR]")
}
fixtureDir := ""
if len(args) == 3 && args[1] == "--fixtures" && args[2] != "" {
fixtureDir = args[2]
} else if len(args) != 1 {
fatal("usage: caveman-engine evals run [--fixtures DIR]")
}View on GitHub (pinned to 3ee70a1026)