oven-sh/bun · error · Error

Cannot derive nonNull on a nonNull type

Error message

Cannot derive nonNull on a nonNull type

What it means

Codegen type-builder guard: the nonNull derivation was requested on a TypeImpl that already has flags.nonNull set. Applying nonNull twice is a no-op at best and usually indicates a duplicated modifier chain in schema code, so the builder throws instead of silently returning an identical type.

Solutions

  1. Remove the duplicate `.nonNull` in the type chain
  2. Verify the parameter is meant to be non-null exactly once
  3. Re-run codegen after cleanup
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    }
    this.assertDefaultIsValid(def);
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      default: def,
    });
  }

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

  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");

View on GitHub (pinned to 8c5296ac45)