oven-sh/bun · error · Error

validateUint32 can only be used on i32 or u32

Error message

validateUint32 can only be used on i32 or u32

What it means

Type-builder guard in the bindgen library: validateUint32() was called on a type whose kind isn't "u32" (and, for its sibling, validateInt32 on non-"i32"). Range validation only applies to matching integer kinds.

Solutions

  1. Change the argument kind to u32
  2. Use validateInt32 for signed i32 or other validators per kind
  3. Re-run codegen after fixing the type
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bindgen-lib-internal.ts:607 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/ef38584edf35f855. Report an issue: GitHub.

Appendix: source

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

      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;
    return enforceRange;
  }
}

export function cAbiIntegerLimits(type: CAbiType) {
  switch (type) {
    case "u8":
      return [0, 255];

View on GitHub (pinned to 8c5296ac45)