larksuite/cli · error

%v overflows %s

Error message

%v overflows %s

What it means

This error fires when a signed integer value is converted to a narrower signed integer type that cannot hold it (reflect's OverflowInt returns true). The typed binder refuses to silently truncate the value, since that would produce wrong API request data. It is thrown from convertReflectValue during typed field binding when a caller-supplied value is coerced to the target Go type.

Source

Thrown at shortcuts/common/typed_binder.go:243

			}
			result.Index(i).Set(reflect.ValueOf(value))
		}
		if target.Kind() == reflect.Array {
			array := reflect.New(target).Elem()
			reflect.Copy(array, result)
			return array.Interface(), nil
		}
		return result.Convert(target).Interface(), nil
	}
	if rawValue.Type().ConvertibleTo(target) {
		converted := reflect.New(target).Elem()
		if isSignedIntegerKind(rawValue.Kind()) && isUnsignedIntegerKind(target.Kind()) {
			if rawValue.Int() < 0 || converted.OverflowUint(uint64(rawValue.Int())) {
				return nil, fmt.Errorf("%v cannot be represented as %s", raw, target)
			}
		}
		if isSignedIntegerKind(rawValue.Kind()) && isSignedIntegerKind(target.Kind()) && converted.OverflowInt(rawValue.Int()) {
			return nil, fmt.Errorf("%v overflows %s", raw, target)
		}
		if isUnsignedIntegerKind(rawValue.Kind()) && isUnsignedIntegerKind(target.Kind()) && converted.OverflowUint(rawValue.Uint()) {
			return nil, fmt.Errorf("%v overflows %s", raw, target)
		}
		return rawValue.Convert(target).Interface(), nil
	}
	encoded, err := json.Marshal(raw)
	if err != nil {
		return nil, err
	}
	value := reflect.New(target)
	if err := json.Unmarshal(encoded, value.Interface()); err != nil {
		return nil, err
	}
	return value.Elem().Interface(), nil
}

func assignCompiledField(root reflect.Value, field compiledInputField, value any, provided bool) error {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Change the target field type to a wider signed integer (int64) that can hold the value.
  2. Clamp or validate the value in the caller before binding so it fits the target type.
  3. If the source value is already the right magnitude, fix the source (e.g. pass milliseconds not nanoseconds).

Example fix

// before
type Req struct {
    Deadline int32 `json:"deadline"`
}
req := Req{Deadline: int32(time.Now().UnixMilli())} // overflows int32

// after
type Req struct {
    Deadline int64 `json:"deadline"`
}
req := Req{Deadline: time.Now().UnixMilli()}
Defensive patterns

Strategy: validation

Validate before calling

func fitsInt32(v int64) bool { return v >= math.MinInt32 && v <= math.MaxInt32 } // adjust bounds to the declared target type before binding

Type guard

func asInt32(v any) (int32, bool) { n, ok := v.(int64); if !ok || n < math.MinInt32 || n > math.MaxInt32 { return 0, false }; return int32(n), true }

Try / catch

if err := binder.Set("deadline", ts); err != nil {
    if strings.Contains(err.Error(), "overflows") {
        return fmt.Errorf("deadline %d too large for field type: %w", ts, err)
    }
    return err
}

Prevention

When it happens

Trigger: Passing a signed integer (e.g. int64 or int) as a field value whose declared target type is a smaller signed type (int8/int16/int32), where the value exceeds the target range — e.g. value 300 into an int8 field, or 5000000000 into an int32 field.

Common situations: Developers bind IDs, timestamps, or byte counts from JSON/config into typed struct fields; a millis timestamp or large snowflake ID (which needs int64) assigned to an int32 field overflows. Also common after switching a struct field from int64 to int without updating callers.

Related errors


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