{"record":{"id":"21a20b6cdac8327a","repo":"denoland/deno","slug":"prefix-when-underlying-source-is-bytes-stra","errorCode":null,"errorMessage":"${prefix}: When underlying source is \"bytes\", strategy.size must be 'undefined'","messagePattern":"(.+?): When underlying source is \"bytes\", strategy\\.size must be 'undefined'","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/web/06_streams.js","lineNumber":6081,"sourceCode":"        strategy,\n        prefix,\n        \"Argument 2\",\n      )\n      : {};\n\n    const underlyingSourceDict = underlyingSource !== undefined\n      ? webidl.converters.UnderlyingSource(\n        underlyingSource,\n        prefix,\n        \"underlyingSource\",\n      )\n      : {};\n    this[_brand] = _brand;\n\n    initializeReadableStream(this);\n    if (underlyingSourceDict.type === \"bytes\") {\n      if (strategy.size !== undefined) {\n        throw new RangeError(\n          `${prefix}: When underlying source is \"bytes\", strategy.size must be 'undefined'`,\n        );\n      }\n      const highWaterMark = extractHighWaterMark(strategy, 0);\n      setUpReadableByteStreamControllerFromUnderlyingSource(\n        // @ts-ignore cannot easily assert this is ReadableStream<ArrayBuffer>\n        this,\n        underlyingSource,\n        underlyingSourceDict,\n        highWaterMark,\n      );\n    } else {\n      const sizeAlgorithm = extractSizeAlgorithm(strategy);\n      const highWaterMark = extractHighWaterMark(strategy, 1);\n      setUpReadableStreamDefaultControllerFromUnderlyingSource(\n        this,\n        underlyingSource,\n        underlyingSourceDict,","sourceCodeStart":6063,"sourceCodeEnd":6099,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/06_streams.js#L6063-L6099","documentation":"RangeError from the ReadableStream constructor: when underlyingSource.type is 'bytes', the queuing strategy must not define a size function (strategy.size !== undefined). Byte streams measure chunks by byte length internally and use a byte-count highWaterMark (default 0), so a custom size would be meaningless; the spec forbids it rather than ignoring it.","triggerScenarios":"new ReadableStream({ type: 'bytes', ... }, { size: (c) => c.byteLength, highWaterMark }) — including size functions copied from value-stream code; a shared STRATEGY constant passed to both kinds of streams; a strategy-builder helper that always sets size.","commonSituations":"Refactoring a value stream into a byte stream while keeping its strategy; shared option objects across a codebase; TypeScript types that suggest size is always allowed.","solutions":["Pass only { highWaterMark } for byte streams — drop the size key.","Build strategies conditionally: include size only when the source type is not 'bytes'.","Strip the key before constructing: const { size, ...rest } = strategy; new ReadableStream(src, rest)."],"exampleFix":"// before\nnew ReadableStream(byteSource, { size: (c) => c.byteLength, highWaterMark: 1024 }); // RangeError\n\n// after\nnew ReadableStream(byteSource, { highWaterMark: 1024 }); // size omitted","handlingStrategy":"validation","validationCode":"function byteStreamStrategy(hwm) {\n  return { highWaterMark: hwm ?? 0 }; // byte streams must not carry a size fn\n}\nnew ReadableStream({ type: 'bytes', ...source }, byteStreamStrategy(1024));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Byte streams quantify backpressure in bytes automatically — size is rejected.","Use one strategy-builder helper per stream type instead of shared strategy constants.","Strip size (const { size, ...rest } = strategy) when a strategy may flow into byte streams."],"tags":["readable-stream","byte-stream","constructor","queuing-strategy","validation"],"backgroundTag":"readablestream-constructor-validation","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}