{"record":{"id":"3ba984b83cc9f7db","repo":"denoland/deno","slug":"err-out-of-range-3ba984","errorCode":"ERR_OUT_OF_RANGE","errorMessage":"The value of \"start\" is out of range. It must be <= \"end\" (here: ${this.end}). Received ${actual}","messagePattern":"The value of \"start\" is out of range\\. It must be <= \"end\" \\(here: (.+?)\\)\\. Received (.+?)","errorType":"exception","errorClass":"NodeRangeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/fs/streams.mjs","lineNumber":254,"sourceCode":"  }\n\n  this.start = options.start;\n  this.end = options.end ?? NumberPOSITIVE_INFINITY;\n  this.pos = undefined;\n  this.bytesRead = 0;\n  this[kIsPerformingIO] = false;\n\n  if (this.start !== undefined) {\n    validateInteger(this.start, \"start\", 0);\n\n    this.pos = this.start;\n  }\n\n  if (this.end !== NumberPOSITIVE_INFINITY) {\n    validateInteger(this.end, \"end\", 0);\n\n    if (this.start !== undefined && this.start > this.end) {\n      throw new ERR_OUT_OF_RANGE(\n        \"start\",\n        `<= \"end\" (here: ${this.end})`,\n        this.start,\n      );\n    }\n  }\n\n  ReflectApply(lazyStream().Readable, this, [options]);\n}\n\nObjectSetPrototypeOf(ReadStream.prototype, lazyStream().Readable.prototype);\nObjectSetPrototypeOf(ReadStream, lazyStream().Readable);\n\nObjectDefineProperty(ReadStream.prototype, \"autoClose\", {\n  __proto__: null,\n  get() {\n    return this._readableState.autoDestroy;\n  },","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/fs/streams.mjs#L236-L272","documentation":"In the ReadStream constructor, start is validated as an integer >= 0 and, whenever end is not Infinity, start must not exceed end. A byte window whose first byte lies past its last byte cannot be read, so construction fails with ERR_OUT_OF_RANGE reporting the actual end value.","triggerScenarios":"fs.createReadStream(f, { start: 100, end: 50 }); range math that swaps the bounds or derives end from a shorter content-length; { start: -1 } also fails earlier via validateInteger.","commonSituations":"HTTP Range-request handlers translating headers into stream options; download resume logic where start equals the new file size but end was computed from the old size; reversed pagination indexes from a UI feeding a file slicer.","solutions":["Fix the range so start <= end — usually the two bounds are swapped.","Omit end when reading to EOF; it defaults to Infinity and the comparison is skipped.","Clamp defensively before constructing: start = Math.min(start, end)."],"exampleFix":"// before\nconst s = fs.createReadStream(f, { start: 100, end: 50 }); // throws\n\n// after\nconst s = fs.createReadStream(f, { start: 50, end: 100 });\n// or read to EOF from an offset\nconst s = fs.createReadStream(f, { start: 50 });","handlingStrategy":"validation","validationCode":"function validRange(o = {}) {\n  const end = o.end ?? Infinity;\n  if (o.start === undefined) return true;\n  return Number.isInteger(o.start) && o.start >= 0 && o.start <= end;\n}\nif (!validRange(opts)) throw new RangeError('start must be an integer >= 0 and <= end');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute ranges from a single source of truth such as stat().size.","Sort unknown-order bounds before use: [a, b].sort((x, y) => x - y).","Log start/end right before createReadStream in range-serving code."],"tags":["filesystem","streams","range","out-of-range","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}