JuliusBrussee/caveman · error

JSON number exponent exceeds supported range

Error message

JSON number exponent exceeds supported range

What it means

parseJSONExponent throws when the exponent's absolute value exceeds maxJSONBNumberExponent while parsing digit by digit with overflow protection. PostgreSQL numeric supports exponents only within a bounded range; exponents beyond it (e.g. 1e999999999) cannot be represented, so the library rejects the literal before reaching the database.

Solutions

  1. Clamp or quantize the value into the supported exponent range before inserting.
  2. Represent out-of-range values as strings or as separate mantissa/exponent fields in detail.
  3. Cap exponents at the producer side (format with limited precision/exponent).
  4. Reject such payloads at the API boundary with a clear client-facing message.

Example fix

// before
detail := []byte(`{"v": 1e1000000}`)
// after
detail := []byte(`{"v": "1e1000000"}`) // or clamp to 0 / MaxFloat64 semantics
Defensive patterns

Strategy: validation

Validate before calling

func exponentInRange(lit string) bool {
	i := strings.IndexAny(lit, "eE")
	if i < 0 { return true }
	e, err := strconv.Atoi(lit[i+1:])
	return err == nil && e <= maxJSONBNumberExponent && e >= -maxJSONBNumberExponent
}

Try / catch

if !exponentInRange(lit) {
	// clamp value or serialize as string field
	return nil
}

Prevention

When it happens

Trigger: canonicalizeJSONNumber -> normalizeJSONNumber on a literal with an enormous exponent such as 1e1000000 or 5e-999999999, where |exponent| > maxJSONBNumberExponent.

Common situations: Scientific-computation output (astronomically large/small values), bignum libraries serializing to scientific notation with unbounded exponents, adversarial or fuzzed JSON payloads.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

	if len(raw) == 0 {
		return 0, fmt.Errorf("invalid JSON number exponent")
	}
	negative := false
	if raw[0] == '+' || raw[0] == '-' {
		negative = raw[0] == '-'
		raw = raw[1:]
	}
	if len(raw) == 0 {
		return 0, fmt.Errorf("invalid JSON number exponent")
	}
	value := 0
	for i := 0; i < len(raw); i++ {
		if raw[i] < '0' || raw[i] > '9' {
			return 0, fmt.Errorf("invalid JSON number exponent")
		}
		digit := int(raw[i] - '0')
		if value > (maxJSONBNumberExponent-digit)/10 {
			return 0, fmt.Errorf("JSON number exponent exceeds supported range")
		}
		value = value*10 + digit
	}
	if negative {
		return -value, nil
	}
	return value, nil
}

// formatTime pins the created_at representation: UTC, microsecond resolution
// (Postgres TIMESTAMPTZ stores microseconds, so truncating here makes the value
// hashed at write time equal the value read back at verify time), RFC3339Nano.
func formatTime(t time.Time) string {
	return t.UTC().Truncate(time.Microsecond).Format(time.RFC3339Nano)
}

// RowHash computes the pinned canonical row hash:
//

View on GitHub (pinned to 3ee70a1026)