{"record":{"id":"eb1f9016965f32f1","repo":"denoland/deno","slug":"autoallocatechunksize-must-be-greater-than-0","errorCode":null,"errorMessage":"\"autoAllocateChunkSize\" must be greater than 0","messagePattern":"\"autoAllocateChunkSize\" must be greater than 0","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/web/06_streams.js","lineNumber":4400,"sourceCode":"  let startAlgorithm = _defaultStartAlgorithm;\n  /** @type {() => Promise<void>} */\n  let pullAlgorithm = _defaultPullAlgorithm;\n  /** @type {(reason: any) => Promise<void>} */\n  let cancelAlgorithm = _defaultCancelAlgorithm;\n  controller[_underlyingSource] = underlyingSource;\n  controller[_underlyingSourceDict] = underlyingSourceDict;\n  if (underlyingSourceDict.start !== undefined) {\n    startAlgorithm = underlyingSourceStartByte;\n  }\n  if (underlyingSourceDict.pull !== undefined) {\n    pullAlgorithm = underlyingSourcePullByte;\n  }\n  if (underlyingSourceDict.cancel !== undefined) {\n    cancelAlgorithm = underlyingSourceCancelByte;\n  }\n  const autoAllocateChunkSize = underlyingSourceDict[\"autoAllocateChunkSize\"];\n  if (autoAllocateChunkSize === 0) {\n    throw new TypeError('\"autoAllocateChunkSize\" must be greater than 0');\n  }\n  setUpReadableByteStreamController(\n    stream,\n    controller,\n    startAlgorithm,\n    pullAlgorithm,\n    cancelAlgorithm,\n    highWaterMark,\n    autoAllocateChunkSize,\n  );\n}\n\n/**\n * @template R\n * @param {ReadableStream<R>} stream\n * @param {ReadableStreamDefaultController<R>} controller\n * @param {(controller: ReadableStreamDefaultController<R>) => void | Promise<void>} startAlgorithm\n * @param {(controller: ReadableStreamDefaultController<R>) => Promise<void> | undefined} pullAlgorithm","sourceCodeStart":4382,"sourceCodeEnd":4418,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/06_streams.js#L4382-L4418","documentation":"The ReadableStream constructor rejected underlyingSource.autoAllocateChunkSize === 0 for a type: 'bytes' stream. autoAllocateChunkSize sets the size of the views the controller auto-allocates for byobRequest when the source is pulled without BYOB reads; zero would allocate nothing, so it must be a positive integer or absent. The option converts as unsigned long long, so negatives fail earlier during argument conversion — only exactly 0 reaches this check.","triggerScenarios":"new ReadableStream({ type: 'bytes', autoAllocateChunkSize: 0 }); passing a computed chunk size (config value, env var, CLI flag) that defaults or coerces to 0; passing 0 intending 'automatic/default'.","commonSituations":"Config-driven stream tuning where a missing key coerces to 0; object literals copied with placeholder zeros; refactors that move the size into a variable initialized to 0.","solutions":["Omit autoAllocateChunkSize entirely (it is optional) or set a positive size such as 64 * 1024.","Validate config before constructing: use the key only when the value is a positive integer.","If you meant 'no auto-allocation', leave the key out and rely on BYOB readers only."],"exampleFix":"// before\nnew ReadableStream({ type: 'bytes', autoAllocateChunkSize: 0 }); // TypeError\n\n// after\nnew ReadableStream({ type: 'bytes', autoAllocateChunkSize: 64 * 1024 });\n// or omit the key entirely","handlingStrategy":"validation","validationCode":"const chunkSize = Number(cfg.autoAllocateChunkSize);\nconst source = {\n  type: 'bytes',\n  ...(Number.isInteger(chunkSize) && chunkSize > 0\n    ? { autoAllocateChunkSize: chunkSize }\n    : {}),\n};\nconst stream = new ReadableStream(source);","typeGuard":null,"tryCatchPattern":"try {\n  stream = new ReadableStream(source);\n} catch (e) {\n  if (e instanceof TypeError && e.message.includes('autoAllocateChunkSize')) {\n    delete source.autoAllocateChunkSize;\n    stream = new ReadableStream(source); // retry without the option\n  } else throw e;\n}","preventionTips":["For this option 0 is invalid while undefined means 'absent' — do not coerce.","Centralize stream option validation instead of spreading raw config into constructors."],"tags":["readable-stream","byte-stream","constructor","autoallocatechunksize","validation"],"backgroundTag":"readablestream-constructor-validation","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}