JuliusBrussee/caveman · error
proposalrun: detail contains trailing data
Error message
proposalrun: detail contains trailing data: %w
What it means
After successfully decoding one JSON value, CanonicalDetail performs a second Decode to confirm nothing follows; if that second Decode returns a non-EOF error (rather than a second value), the trailing data was unparseable garbage and this wrapped error is returned. Like the trailing-JSON error, it guards the determinism required for RowHash.
Solutions
- Locate and remove the trailing garbage after the first JSON value in the detail payload
- Fix the writer responsible for the truncated/corrupt append
- Check storage/transfer paths (column size limits, streaming truncation) that may cut payloads mid-write
- Validate payloads with json.Decoder EOF checks before hashing
Defensive patterns
Strategy: validation
Validate before calling
var v json.RawMessage
if err := json.Unmarshal(detail, &v); err != nil { return err }
if len(bytes.TrimSpace(detail)) != len(bytes.TrimSpace(v)) { return errors.New("detail has trailing data") } Try / catch
if _, err := CanonicalDetail(detail); err != nil {
if strings.Contains(err.Error(), "trailing data") {
// payload corrupted after first JSON value: recover from source system or re-derive
}
return err
} Prevention
- Write detail payloads atomically (single UPDATE) rather than appending bytes
- Check for truncation on transfer/storage paths (column limits, streaming cut-offs)
- Validate stored details periodically with a decoder EOF check
When it happens
Trigger: Calling CanonicalDetail/RowHash with a valid JSON value followed by malformed bytes, e.g. '{"a":1}garbage' or a truncated second fragment.
Common situations: A partially-written append corrupted the payload after the first JSON value; byte-level truncation during transfer/storage; binary data concatenated onto a JSON document.
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 JSON
- proposalrun: detail is not valid 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/3c669d6a6671bd65.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/proposalrun/proposalrun.go:71
// 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
}
// PostgreSQL jsonb stores JSON numbers using its numeric type. These are the
// documented numeric bounds (131072 digits before and 16383 after the decimal
// point); rejecting at the canonicalization boundary keeps write and read-back
// hashing deterministic and avoids unbounded strings from hostile exponents.
// maxJSONBNumberExponent is an additional allocation guard. PostgreSQL can
// accept some zero literals with a larger positive exponent after normalizingView on GitHub (pinned to 3ee70a1026)