larksuite/cli · error

%s number constraints must be finite

Error message

%s number constraints must be finite

What it means

validateShape rejects a typedNumberShape whose Enum values, Minimum, or Maximum are NaN or +/-Inf. Floating-point specials cannot be represented in JSON schema constraints, so the declaration is refused at startup; the message includes the shape path.

Source

Thrown at shortcuts/common/typed_compile_data.go:277

	}
	switch value := shape.(type) {
	case anyJSONShape:
	case typedStringShape:
		if value.MinLength != nil && *value.MinLength < 0 || value.MaxLength != nil && *value.MaxLength < 0 {
			return fmt.Errorf("%s string lengths must be nonnegative", path)
		}
		if value.MinLength != nil && value.MaxLength != nil && *value.MinLength > *value.MaxLength {
			return fmt.Errorf("%s minLength exceeds maxLength", path)
		}
	case typedBooleanShape:
	case typedIntegerShape:
		if value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {
			return fmt.Errorf("%s minimum exceeds maximum", path)
		}
	case typedNumberShape:
		for _, number := range append(append([]float64{}, value.Enum...), pointerFloats(value.Minimum, value.Maximum)...) {
			if math.IsNaN(number) || math.IsInf(number, 0) {
				return fmt.Errorf("%s number constraints must be finite", path)
			}
		}
		if value.Minimum != nil && value.Maximum != nil && *value.Minimum > *value.Maximum {
			return fmt.Errorf("%s minimum exceeds maximum", path)
		}
	case typedNullShape:
	case typedConstShape:
		if _, err := json.Marshal(value.Value); err != nil {
			return fmt.Errorf("%s const is not JSON-encodable: %w", path, err)
		}
	case typedArrayShape:
		if value.Items == nil {
			return fmt.Errorf("%s.Items is required", path)
		}
		if value.MinItems != nil && *value.MinItems < 0 || value.MaxItems != nil && *value.MaxItems < 0 {
			return fmt.Errorf("%s item lengths must be nonnegative", path)
		}
		if value.MinItems != nil && value.MaxItems != nil && *value.MinItems > *value.MaxItems {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Inspect Enum, Minimum, and Maximum at the reported path; replace any NaN/Inf with finite values.
  2. Use nil pointers instead of NaN/Inf to express 'no bound'.
  3. Validate computed bounds with math.IsFinite before building the shape.
  4. Fix the upstream source (config, constants) producing the special value.

Example fix

// before
limit := math.MaxFloat64 * 2 // +Inf
shape := typedNumberShape{Maximum: &limit}
// after
shape := typedNumberShape{} // no bound, or a finite maximum
Defensive patterns

Strategy: validation

Validate before calling

func finiteFloat(p *float64) bool { return p == nil || !math.IsNaN(*p) && !math.IsInf(*p, 0) }
func validNumberShape(s typedNumberShape) bool {
    if !finiteFloat(s.Minimum) || !finiteFloat(s.Maximum) { return false }
    for _, e := range s.Enum { if math.IsNaN(e) || math.IsInf(e, 0) { return false } }
    return true
}
// if !validNumberShape(shape) { return errors.New("non-finite number constraint") }

Type guard

func isFinite(f float64) bool { return !math.IsNaN(f) && !math.IsInf(f, 0) }

Prevention

When it happens

Trigger: An explicit Output.Data.Shape or DataField.Shape override declares typedNumberShape with a NaN/Inf in Enum, Minimum, or Maximum; or parseFiniteFloatBits-adjacent code paths / programmatic computation inject math.Inf or math.NaN into the shape.

Common situations: Computing a bound via division by zero or a sentinel value like math.MaxFloat64 misuse; loading limits from config where a missing value decodes to Inf; accidentally using NaN as an 'unset' marker instead of nil.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/582517234603ff3d. Report an issue: GitHub.