oven-sh/bun · error · Error

Wrong length

Error message

Wrong length

What it means

A generic 'input or state is invalid' sentinel declared in the install error enum (src/install/error.rs:183-184). It currently has no production construction sites in this tree, so an occurrence implies an older/alternative code path rejected something as invalid without a more specific variant.

Source

Thrown at bench/snippets/buffer-concat.mjs:29

  const check = true;

  const buffers = [first, second, third];

  const fmt =
    size > 1024 * 1024
      ? new Intl.NumberFormat(undefined, { unit: "megabyte", style: "unit" })
      : size > 1024
        ? new Intl.NumberFormat(undefined, { unit: "kilobyte", style: "unit" })
        : new Intl.NumberFormat(undefined, { unit: "byte", style: "unit" });

  bench(
    `Buffer.concat(${fmt.format(
      Number((size > 1024 * 1024 ? size / 1024 / 1024 : size > 1024 ? size / 1024 : size).toFixed(2)),
    )} x 3)`,
    () => {
      const result = Buffer.concat(buffers);
      if (check) {
        if (result.byteLength != size * 3) throw new Error("Wrong length");
        if (result[0] != 1) throw new Error("Wrong first byte");
        if (result[size] != 2) throw new Error("Wrong second byte");
        if (result[size * 2] != 3) throw new Error("Wrong third byte");

        result[0] = 10;
        if (first[0] != 1) throw new Error("First buffer was modified");

        result[size] = 20;
        if (second[0] != 2) throw new Error("Second buffer was modified");

        result[size * 2] = 30;
        if (third[0] != 3) throw new Error("Third buffer was modified");
      }
    },
  );
}

const chunk = Buffer.alloc(16);

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Upgrade Bun to the latest version
  2. If it reproduces on current Bun, capture the exact command + lockfile and file an issue at https://github.com/oven-sh/bun/issues
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await Bun.$`bun install`;
} catch (err) {
  console.error("install failed:", err.stderr?.toString() ?? err);
  process.exit(1);
}

Prevention

When it happens

Trigger: None reachable from current Bun code paths; reserved for generic invalid-input outcomes.

Common situations: Seeing it in practice almost certainly means an outdated Bun build or an internal bug path.

Related errors


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