JuliusBrussee/caveman · error
proposalrun: detail is not valid JSON
Error message
proposalrun: detail is not valid JSON: %w
What it means
CanonicalDetail parses a proposal-run 'detail' JSON payload into a canonical, deterministic form (numbers preserved via UseNumber) so RowHash can hash it consistently. This error is thrown when the detail bytes are not valid JSON at all — the decoder fails on the first Decode. The library needs well-formed JSON to produce a stable canonical representation.
Solutions
- Inspect the wrapped json error for the exact offset/syntax problem in the detail payload
- Fix the producer that wrote the detail to always marshal valid JSON before storage
- For existing corrupt rows, repair or re-derive the detail and re-run RowHash
- Validate JSON (e.g. json.Valid(detail)) before calling CanonicalDetail if inputs are untrusted
Example fix
// before
hash, err := RowHash(row) // detail column holds "{'a':1}" (single quotes) -> not valid JSON
// after
if !json.Valid(detail) {
return fmt.Errorf("invalid detail payload for run %s", runID)
}
hash, err := RowHash(row) Defensive patterns
Strategy: validation
Validate before calling
if len(detail) == 0 || !json.Valid(detail) {
return errors.New("detail payload is not valid JSON")
}
hash, err := RowHash(row) Try / catch
hash, err := RowHash(row)
if err != nil {
var jsonErr *json.SyntaxError
if errors.As(err, &jsonErr) && strings.Contains(err.Error(), "not valid JSON") {
// quarantine row for re-derivation; jsonErr.Offset points at the bad byte
}
return err
} Prevention
- Always write detail fields with json.Marshal; never interpolate strings
- Add a NOT NULL + JSONB column type or app-level json.Valid check on write
- Alert on rows whose detail fails json.Valid in data-quality checks
When it happens
Trigger: Calling CanonicalDetail (directly or via RowHash) with a []byte/string detail that is malformed JSON: truncated payload, HTML error page stored in the detail column, concatenation artifacts, or non-UTF8 garbage.
Common situations: A writer stored partially-written JSON in the proposal run detail column; a migration or ETL job mangled the payload; code passed a Go string (not JSON) instead of marshaled bytes; encoding issues from a upstream API response.
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
- proposalrun: detail contains trailing data
- proposalrun: detail contains trailing JSON
- caveman agent: value is not canonically serializable
- array not closed
- assembly slot content is not JSON-serializable
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/f9e32a30a9405fbf.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/proposalrun/proposalrun.go:64
//
// Numbers are decoded with Decoder.UseNumber and normalized by exact decimal
// coefficient/exponent arithmetic, so they never round through float64. The
// canonical form is a plain decimal with insignificant zeroes removed; zero is
// always "0". Thus storage-equivalent spellings (for example 1, 1.0, and 1e0)
// hash identically, while adjacent arbitrary-precision integers remain
// distinct. The bounds mirror PostgreSQL's numeric-backed jsonb limits and
// reject values that could not be persisted there before allocating output.
// The decoder enforces the JSON number grammar (including rejecting NaN/Inf),
// and a second decode below rejects any trailing value or non-whitespace data.
func CanonicalDetail(detail json.RawMessage) ([]byte, error) {
if len(detail) == 0 {
return []byte("{}"), nil
}
var v any
dec := json.NewDecoder(bytes.NewReader(detail))
dec.UseNumber()
if err := dec.Decode(&v); err != nil {
return nil, fmt.Errorf("proposalrun: detail is not valid JSON: %w", err)
}
var trailing any
if err := dec.Decode(&trailing); err != io.EOF {
if err == nil {
return nil, fmt.Errorf("proposalrun: detail contains trailing JSON")
}
return nil, fmt.Errorf("proposalrun: detail contains trailing data: %w", err)
}
v, err := canonicalizeJSONValue(v)
if err != nil {
return nil, fmt.Errorf("proposalrun: canonicalize detail: %w", err)
}
out, err := json.Marshal(v)
if err != nil {
return nil, fmt.Errorf("proposalrun: marshal canonical detail: %w", err)
}
return out, nil
}View on GitHub (pinned to 3ee70a1026)