{"record":{"id":"f9e32a30a9405fbf","repo":"JuliusBrussee/caveman","slug":"proposalrun-detail-is-not-valid-json-w","errorCode":null,"errorMessage":"proposalrun: detail is not valid JSON: %w","messagePattern":"proposalrun: detail is not valid JSON: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/proposalrun/proposalrun.go","lineNumber":64,"sourceCode":"//\n// Numbers are decoded with Decoder.UseNumber and normalized by exact decimal\n// coefficient/exponent arithmetic, so they never round through float64. The\n// canonical form is a plain decimal with insignificant zeroes removed; zero is\n// always \"0\". Thus storage-equivalent spellings (for example 1, 1.0, and 1e0)\n// hash identically, while adjacent arbitrary-precision integers remain\n// distinct. The bounds mirror PostgreSQL's numeric-backed jsonb limits and\n// reject values that could not be persisted there before allocating output.\n// The decoder enforces the JSON number grammar (including rejecting NaN/Inf),\n// and a second decode below rejects any trailing value or non-whitespace data.\nfunc CanonicalDetail(detail json.RawMessage) ([]byte, error) {\n\tif len(detail) == 0 {\n\t\treturn []byte(\"{}\"), nil\n\t}\n\tvar v any\n\tdec := json.NewDecoder(bytes.NewReader(detail))\n\tdec.UseNumber()\n\tif err := dec.Decode(&v); err != nil {\n\t\treturn nil, fmt.Errorf(\"proposalrun: detail is not valid JSON: %w\", err)\n\t}\n\tvar trailing any\n\tif err := dec.Decode(&trailing); err != io.EOF {\n\t\tif err == nil {\n\t\t\treturn nil, fmt.Errorf(\"proposalrun: detail contains trailing JSON\")\n\t\t}\n\t\treturn nil, fmt.Errorf(\"proposalrun: detail contains trailing data: %w\", err)\n\t}\n\tv, err := canonicalizeJSONValue(v)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"proposalrun: canonicalize detail: %w\", err)\n\t}\n\tout, err := json.Marshal(v)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"proposalrun: marshal canonical detail: %w\", err)\n\t}\n\treturn out, nil\n}","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/proposalrun/proposalrun.go#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nhash, err := RowHash(row) // detail column holds \"{'a':1}\" (single quotes) -> not valid JSON\n// after\nif !json.Valid(detail) {\n    return fmt.Errorf(\"invalid detail payload for run %s\", runID)\n}\nhash, err := RowHash(row)","handlingStrategy":"validation","validationCode":"if len(detail) == 0 || !json.Valid(detail) {\n    return errors.New(\"detail payload is not valid JSON\")\n}\nhash, err := RowHash(row)","typeGuard":null,"tryCatchPattern":"hash, err := RowHash(row)\nif err != nil {\n    var jsonErr *json.SyntaxError\n    if errors.As(err, &jsonErr) && strings.Contains(err.Error(), \"not valid JSON\") {\n        // quarantine row for re-derivation; jsonErr.Offset points at the bad byte\n    }\n    return err\n}","preventionTips":["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"],"tags":["json","hashing","data-integrity","proposalrun"],"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"}