JuliusBrussee/caveman · error

not losslessly TOON-encodable (invalid JSON, or nested/non-u

Error message

not losslessly TOON-encodable (invalid JSON, or nested/non-uniform shape); keep JSON

What it means

Error "not losslessly TOON-encodable (invalid JSON, or nested/non-uniform shape); keep JSON" thrown in JuliusBrussee/caveman.

Source

Thrown at engine/toon.go:15

package engine

import (
	"encoding/json"
	"fmt"

	"github.com/JuliusBrussee/caveman/engine/compressors"
)

// EncodeTOON converts JSON to the lossless TOON subset without CCR or size
// gating. It is for explicit agent/CLI requests, not automatic proxy routing.
func (e *Engine) EncodeTOON(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
}

// DecodeTOON converts TOON back to compact JSON. Malformed TOON fails closed.
func (e *Engine) DecodeTOON(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
}

View on GitHub (pinned to 27d5a3981a)

Solutions

  1. Keep the payload as JSON; it is not losslessly TOON-encodable.

When it happens

Trigger: Thrown at engine/toon.go:15 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of JuliusBrussee/caveman@27d5a3981a (2026-08-15). Data as JSON: /api/errors/710a89dca91c5e33. Report an issue: GitHub.