nodejs/node · error · InvalidArgumentError
UND_ERR_INVALID_ARG
UND_ERR_INVALID_ARG
Error message
maxSize must be a number greater than 0
What it means
Thrown by the dump interceptor's `DumpHandler` constructor (`InvalidArgumentError`, code `UND_ERR_INVALID_ARG`) when `maxSize` is provided and is either not finite or less than 1. The dump interceptor reads and discards response bodies up to a cap so that request hooks (redirect handling, retry decisions) can see the response without buffering huge payloads; `maxSize` (default 1 MiB) is the byte ceiling it enforces. Values below 1 or non-finite (`NaN`, `Infinity`) are rejected because they make the cap meaningless.
Source
Thrown at deps/undici/src/lib/interceptor/dump.js:16
'use strict'
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
const DecoratorHandler = require('../handler/decorator-handler')
class DumpHandler extends DecoratorHandler {
#maxSize = 1024 * 1024
#dumped = false
#size = 0
#controller = null
aborted = false
reason = false
constructor ({ maxSize, signal }, handler) {
if (maxSize != null && (!Number.isFinite(maxSize) || maxSize < 1)) {
throw new InvalidArgumentError('maxSize must be a number greater than 0')
}
super(handler)
this.#maxSize = maxSize ?? this.#maxSize
// this.#handler = handler
}
#abort (reason) {
this.aborted = true
this.reason = reason
}
onRequestStart (controller, context) {
controller.abort = this.#abort.bind(this)
this.#controller = controller
return super.onRequestStart(controller, context)View on GitHub (pinned to 1b2de5e052)
Solutions
- Pass a finite integer ≥1, e.g. `maxSize: 4 * 1024 * 1024` for 4 MiB.
- If loading from config/env, coerce with `Number(...)` and check `Number.isFinite(v) && v >= 1`.
- To use the default, omit the option entirely (1 MiB default applies).
Example fix
// before
new DumpHandler({ maxSize: 0 }, handler)
dispatch({ ..., dumpMaxSize: process.env.DUMP_SIZE })
// after
new DumpHandler({ maxSize: 2 * 1024 * 1024 }, handler)
dispatch({ ..., dumpMaxSize: Number(process.env.DUMP_SIZE) }) Defensive patterns
Strategy: validation
Validate before calling
function validateMaxSize(v) {
if (v == null) return undefined
const n = Number(v)
if (!Number.isFinite(n) || n < 1) {
throw new Error('maxSize must be a finite number >= 1')
}
return n
} Type guard
function isValidMaxSize(v) {
return typeof v === 'number' && Number.isFinite(v) && v >= 1
} Prevention
- Never pass 0 to 'disable' dumping.
- Coerce env-derived sizes with Number() and parse units.
When it happens
Trigger: Passing `maxSize: 0`, a negative number, `NaN`, a string, or `Infinity`. Constructed via `new DumpHandler({ maxSize }, handler)` or through the interceptor with `dumpMaxSize` in dispatch opts. Note the constructor checks `maxSize < 1`, so the minimum is 1 byte.
Common situations: Setting `dumpMaxSize: 0` intending 'don't dump' (it errors instead); reading the cap from env as a string; passing a human-readable size. The interceptor's `createDumpInterceptor` reads `opts.dumpMaxSize`, so the validation surfaces when you dispatch with an invalid per-request override.
Related errors
- expected opts.maxBufferSize to be a positive finite number,
- expected opts.methods to be an array, got ${typeof methods}
- expected opts.skipHeaderNames to be an array, got ${typeof s
- expected opts.excludeHeaderNames to be an array, got ${typeo
- Invalid maxTTL. Must be a positive number
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/28ccaf64e329f654.
Report an issue: GitHub.