oven-sh/bun · error · Error

validateInt32 can only be used on i32 or u32

Error message

validateInt32 can only be used on i32 or u32

What it means

Bindgen DSL guard: `.validateInt32(...)` was called on a type whose kind is not i32 (the message mentions i32 or u32; the implementation currently only accepts i32). Integer range validation is only defined for 32-bit integer ABI types, so the misuse throws at codegen time.

Solutions

  1. Change the argument kind to i32/u32 as appropriate
  2. Use the matching validator for the actual kind (e.g. f64 -> finite/clamp)
  3. Re-run codegen after aligning kind and validator
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bindgen-lib-internal.ts:599 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/1eb529e862c72523. Report an issue: GitHub.

Appendix: source

Thrown at src/codegen/bindgen-lib-internal.ts:599

  }

  enforceRange(min?: number | bigint, max?: number | bigint) {
    return this.#rangeModifier(min, max, "enforce");
  }

  get nonNull() {
    if (this.flags.nonNull) {
      throw new Error("Cannot derive nonNull on a nonNull type");
    }
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      nonNull: true,
    });
  }

  validateInt32(min?: number, max?: number) {
    if (this.kind !== "i32") {
      throw new Error("validateInt32 can only be used on i32 or u32");
    }
    const rangeInfo = cAbiIntegerLimits("i32");
    return this.validateInteger(min ?? rangeInfo[0], max ?? rangeInfo[1]);
  }

  validateUint32(min?: number, max?: number) {
    if (this.kind !== "u32") {
      throw new Error("validateUint32 can only be used on i32 or u32");
    }
    const rangeInfo = cAbiIntegerLimits("u32");
    return this.validateInteger(min ?? rangeInfo[0], max ?? rangeInfo[1]);
  }

  validateInteger(min?: number | bigint, max?: number | bigint) {
    min ??= Number.MIN_SAFE_INTEGER;
    max ??= Number.MAX_SAFE_INTEGER;
    const enforceRange = this.#rangeModifier(min, max, "enforce") as TypeImpl;
    enforceRange.flags.nodeValidator = NodeValidator.validateInteger;

View on GitHub (pinned to 8c5296ac45)