{"record":{"id":"bbc0c156fef0461f","repo":"JuliusBrussee/caveman","slug":"json-number-exceeds-postgresql-fraction-digit-limi","errorCode":null,"errorMessage":"JSON number exceeds PostgreSQL fraction-digit limit","messagePattern":"JSON number exceeds PostgreSQL fraction-digit limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/proposalrun/proposalrun.go","lineNumber":231,"sourceCode":"\t}\n\tfor i := 0; i < len(integerPart); i++ {\n\t\tif integerPart[i] < '0' || integerPart[i] > '9' {\n\t\t\treturn \"\", fmt.Errorf(\"invalid JSON number\")\n\t\t}\n\t}\n\tfor i := 0; i < len(fractionPart); i++ {\n\t\tif fractionPart[i] < '0' || fractionPart[i] > '9' {\n\t\t\treturn \"\", fmt.Errorf(\"invalid JSON number\")\n\t\t}\n\t}\n\t// PostgreSQL numeric retains the input display scale in jsonb output,\n\t// including trailing fractional zeroes. Validate the raw scale before the\n\t// canonical reduction below strips those zeroes; otherwise a value such as\n\t// 1.0000e-16383 would reduce to a representable scale while its original\n\t// jsonb insert would fail at the 16383-digit numeric limit.\n\trawScale := len(fractionPart) - exponent\n\tif rawScale > maxJSONBNumericFractionDigits {\n\t\treturn \"\", fmt.Errorf(\"JSON number exceeds PostgreSQL fraction-digit limit\")\n\t}\n\n\tdigits := strings.TrimLeft(integerPart+fractionPart, \"0\")\n\tif digits == \"\" {\n\t\treturn \"0\", nil\n\t}\n\tscale := len(fractionPart) - exponent\n\tfor scale > 0 && strings.HasSuffix(digits, \"0\") {\n\t\tdigits = digits[:len(digits)-1]\n\t\tscale--\n\t}\n\n\tvar out string\n\tswitch {\n\tcase scale <= 0:\n\t\tzeros := -scale\n\t\tif zeros > maxJSONBNumericIntegerDigits-len(digits) {\n\t\t\treturn \"\", fmt.Errorf(\"JSON number exceeds PostgreSQL integer-digit limit\")","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/proposalrun/proposalrun.go#L213-L249","documentation":"Error from normalizeJSONNumber: the number's fractional display scale (digits after the decimal point, adjusted by exponent) exceeds PostgreSQL numeric's limit. PostgreSQL retains input display scale in jsonb output — including trailing zeroes — so the raw scale is checked before canonical reduction strips zeroes.","triggerScenarios":"Thrown at shared/platform/proposalrun/proposalrun.go:231 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Round or trim trailing fractional zeroes (and excess precision) before storing","Re-express the value in scientific notation with fewer scale digits, or as a string","Validate numeric scale at the ingestion boundary and reject with a domain message"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}