JuliusBrussee/caveman · error

JSON number exceeds PostgreSQL integer-digit limit

Error message

JSON number exceeds PostgreSQL integer-digit limit

What it means

Error from normalizeJSONNumber: after applying the exponent, the integer part would need more zero-padding digits than PostgreSQL numeric's integer-digit ceiling allows. The value's magnitude exceeds what a jsonb-stored numeric can represent.

Solutions

  1. Clamp or cap the magnitude before storage if saturation is acceptable
  2. Store out-of-range magnitudes as strings or decimals in a wider representation
  3. Reject the input upstream with a domain-specific overflow message
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shared/platform/proposalrun/proposalrun.go:249 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/741d996d7c1c6b8f. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/proposalrun/proposalrun.go:249

		return "", fmt.Errorf("JSON number exceeds PostgreSQL fraction-digit limit")
	}

	digits := strings.TrimLeft(integerPart+fractionPart, "0")
	if digits == "" {
		return "0", nil
	}
	scale := len(fractionPart) - exponent
	for scale > 0 && strings.HasSuffix(digits, "0") {
		digits = digits[:len(digits)-1]
		scale--
	}

	var out string
	switch {
	case scale <= 0:
		zeros := -scale
		if zeros > maxJSONBNumericIntegerDigits-len(digits) {
			return "", fmt.Errorf("JSON number exceeds PostgreSQL integer-digit limit")
		}
		out = digits + strings.Repeat("0", zeros)
	case scale >= len(digits):
		if scale > maxJSONBNumericFractionDigits {
			return "", fmt.Errorf("JSON number exceeds PostgreSQL fraction-digit limit")
		}
		out = "0." + strings.Repeat("0", scale-len(digits)) + digits
	default:
		if scale > maxJSONBNumericFractionDigits || len(digits)-scale > maxJSONBNumericIntegerDigits {
			return "", fmt.Errorf("JSON number exceeds PostgreSQL numeric limits")
		}
		point := len(digits) - scale
		out = digits[:point] + "." + digits[point:]
	}
	if negative {
		return "-" + out, nil
	}
	return out, nil

View on GitHub (pinned to 3ee70a1026)