denoland/deno · error · ERR_OUT_OF_RANGE
ERR_OUT_OF_RANGE
ERR_OUT_OF_RANGE
Error message
The value of "percentile" is out of range. It must be > 0 && <= 100. Received ${received} What it means
Histogram.percentile(p) validates 0 < p <= 100. Because the guard is `!(p > 0 && p <= 100)`, NaN and Infinity are also rejected, not just values outside the window. ERR_OUT_OF_RANGE is thrown after the type check passes.
Source
Thrown at ext/node/polyfills/perf_hooks.js:421
MapPrototypeSet(out, 0, this.minBigInt);
for (
let percentile = 50;
percentile < 100;
percentile += (100 - percentile) / 2
) {
MapPrototypeSet(out, percentile, this.percentileBigInt(percentile));
if (percentile > 99.999) break;
}
MapPrototypeSet(out, 100, this.maxBigInt);
}
return out;
}
percentile(p) {
if (typeof p !== "number") {
throw new ERR_INVALID_ARG_TYPE("percentile", "number", p);
}
if (!(p > 0 && p <= 100)) {
throw new ERR_OUT_OF_RANGE("percentile", "> 0 && <= 100", p);
}
return this[_handle].percentile(p);
}
percentileBigInt(p) {
if (typeof p !== "number") {
throw new ERR_INVALID_ARG_TYPE("percentile", "number", p);
}
if (!(p > 0 && p <= 100)) {
throw new ERR_OUT_OF_RANGE("percentile", "> 0 && <= 100", p);
}
return BigInt(this[_handle].percentileBigInt(p));
}
reset() {
this[_handle].reset();
}
toJSON() {
return {
count: this.count,View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Scale fractions by 100 before calling (0.99 → 99)
- Validate first: Number.isFinite(p) && p > 0 && p <= 100
- Fix the NaN source (bad parse, undefined variable) — the range error is often a symptom, not the bug
Example fix
// before h.percentile(ratio); // ratio = 0.99 // after h.percentile(ratio * 100); // 99
Defensive patterns
Strategy: validation
Validate before calling
if (!(Number.isFinite(p) && p > 0 && p <= 100)) {
throw new RangeError(`percentile must be > 0 and <= 100, got ${p}`);
}
return h.percentile(p); Type guard
const isValidPercentile = (p) => Number.isFinite(p) && p > 0 && p <= 100;
Try / catch
try {
v = h.percentile(p);
} catch (err) {
if (err.code === "ERR_OUT_OF_RANGE") {
v = h.percentile(Math.min(Math.max(p, 0.001), 100)); // clamp and retry once
} else throw err;
} Prevention
- Convert ratios to percentages at the boundary (×100)
- Unit-test percentile plumbing with 0, 100, 101, NaN, and negative inputs
When it happens
Trigger: h.percentile(0); h.percentile(101); h.percentile(-5); h.percentile(NaN) (e.g. parseFloat("p50")); h.percentile(Infinity).
Common situations: Passing a fraction (0.5 meaning 50%) instead of a percentage; NaN leaking from failed parses or missing config keys; arithmetic like p = a/b with b = 0.
Related errors
- ERR_ILLEGAL_CONSTRUCTOR
- ERR_INVALID_ARG_TYPE
- Unable to deserialize RecordableHistogram
- Empty filepath.
- resolve hook must return { shortCircuit: true } or call next
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/8d427c0426b4286f.
Report an issue: GitHub.