denoland/deno · error · RangeError

The region specified by view is larger than byobRequest

Error message

The region specified by view is larger than byobRequest

What it means

RangeError from respondWithNewView(view): firstDescriptor.bytesFilled + view.byteLength exceeds firstDescriptor.byteLength. The replacement view covers more bytes than remain unfilled in the pending pull-into, i.e. the region handed back is larger than the request can accept.

Source

Thrown at ext/web/06_streams.js:2828

      throw new TypeError(
        "The view's length must be greater than 0 when calling respondWithNewView() on a readable stream",
      );
    }
  }
  // deno-lint-ignore deno-internal/prefer-primordials
  if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== byteOffset) {
    throw new RangeError(
      "The region specified by view does not match byobRequest",
    );
  }
  if (firstDescriptor.bufferByteLength !== getArrayBufferByteLength(buffer)) {
    throw new RangeError(
      "The buffer of view has different capacity than byobRequest",
    );
  }
  // deno-lint-ignore deno-internal/prefer-primordials
  if (firstDescriptor.bytesFilled + byteLength > firstDescriptor.byteLength) {
    throw new RangeError(
      "The region specified by view is larger than byobRequest",
    );
  }
  firstDescriptor.buffer = ArrayBufferPrototypeTransferToFixedLength(buffer);
  readableByteStreamControllerRespondInternal(controller, byteLength);
}

/**
 * @param {ReadableByteStreamController} controller
 * @returns {PullIntoDescriptor}
 */
function readableByteStreamControllerShiftPendingPullInto(controller) {
  assert(controller[_byobRequest] === null);
  return controller[_pendingPullIntos].dequeue();
}

/**
 * @param {ReadableByteStreamController} controller

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Size the view to the bytes written this step: view.subarray(start, start + n).
  2. Track the fill point alongside the request and respond only with the remaining span.
  3. Prefer respond(n), which validates the total against the descriptor for you.

Example fix

// before
byob.respondWithNewView(byob.view); // whole view, part already filled -> RangeError

// after
const v = byob.view.subarray(0, n); // only the region written now
byob.respondWithNewView(v);
Defensive patterns

Strategy: validation

Validate before calling

// region must fit the remaining unfilled space of the request
if (view.byteLength > byob.view.byteLength) {
  view = view.subarray(0, byob.view.byteLength);
}
byob.respondWithNewView(view);

Try / catch

try {
  byob.respondWithNewView(view);
} catch (e) {
  if (e instanceof RangeError && e.message.includes('larger than byobRequest')) {
    byob.respond(byob.view.byteLength);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Responding with the full original view after partial fills already consumed its head; enlarging the view (subarray with a larger end) before responding; combining several chunks into one oversized region.

Common situations: Partial-write loops that grow the response region; forgetting that bytesFilled advances with earlier responses on the same request; example code that responds with the whole buffer.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/ce02fca7d56708fb. Report an issue: GitHub.