neoclide/coc.nvim · error
maxResponseSize must be a positive finite number
Error message
maxResponseSize must be a positive finite number
What it means
resolveRequestOptions in src/model/fetch.ts applies a response-size cap to every request, defaulting to DEFAULT_MAX_RESPONSE_SIZE when options.maxResponseSize is undefined. If the provided value is not a positive finite number (0, negative, NaN, Infinity), it throws this error before the request is made, protecting against unbounded memory use when buffering responses.
Source
Thrown at src/model/fetch.ts:192
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)',
'Accept-Encoding': 'gzip, deflate',
...(options.headers ?? {})
}
}
if (dataType == 'object') {
opts.headers['Content-Type'] = 'application/json'
} else if (dataType == 'string') {
opts.headers['Content-Type'] = 'text/plain'
}
if (proxyOptions.proxyAuthorization) opts.headers['Proxy-Authorization'] = proxyOptions.proxyAuthorization
if (proxyOptions.proxyCA) opts.ca = fs.readFileSync(proxyOptions.proxyCA)
if (options.user) opts.auth = options.user + ':' + (toText(options.password))
if (url.username) opts.auth = url.username + ':' + (toText(url.password))
if (options.timeout) opts.timeout = options.timeout
if (options.buffer) opts.buffer = true
let maxResponseSize = options.maxResponseSize ?? DEFAULT_MAX_RESPONSE_SIZE
if (!Number.isFinite(maxResponseSize) || maxResponseSize <= 0) throw new Error('maxResponseSize must be a positive finite number')
opts.maxResponseSize = maxResponseSize
return opts
}
/**
* Extract and validate the charset parameter of a Content-Type header.
* Handles quoted values (charset="utf-8") and trailing parameters
* (charset=utf-8; format=flowed); throws for unsupported encodings.
*/
function parseCharset(contentType: string): BufferEncoding {
let match = /;\s*charset\s*=\s*"?([^";\s]+)"?/i.exec(contentType)
let encoding = match ? match[1] : 'utf8'
let lower = encoding.toLowerCase()
if (lower === 'iso-8859-1' || lower === 'latin-1') encoding = 'latin1'
else if (lower === 'utf-16' || lower === 'utf-16le' || lower === 'ucs-2' || lower === 'ucs2') encoding = 'utf16le'
else if (lower === 'us-ascii') encoding = 'ascii'
if (!Buffer.isEncoding(encoding)) {
throw new Error(`Unsupported charset: ${encoding}`)View on GitHub (pinned to 50e974d969)
Solutions
- Pass a positive finite number of bytes, e.g. maxResponseSize: 10 * 1024 * 1024.
- Omit maxResponseSize to use the library default instead of 0 for 'unlimited'.
- Coerce config values: const n = Number(v); if (Number.isFinite(n) && n > 0) use n.
Example fix
// before
fetch(url, { maxResponseSize: 0 })
// after
fetch(url, { maxResponseSize: 50 * 1024 * 1024 }) // or omit the option Defensive patterns
Strategy: validation
Validate before calling
function validMaxResponseSize(v) {
if (v === undefined) return true
return Number.isFinite(v) && v > 0
}
if (!validMaxResponseSize(opts.maxResponseSize))
throw new Error('maxResponseSize must be a positive finite number or undefined') Type guard
function isPositiveFinite(v: unknown): v is number { return typeof v === 'number' && Number.isFinite(v) && v > 0 } Try / catch
try {
return await fetch(url, { maxResponseSize })
} catch (e) {
if (/maxResponseSize must be/.test(e.message)) return fetch(url) // fall back to default limit
throw e
} Prevention
- Use undefined for 'use default'; never 0 or -1.
- Coerce config/env strings with Number() and validate before passing.
- Guard computed sizes: if (!Number.isFinite(n) || n <= 0) delete opts.maxResponseSize.
When it happens
Trigger: Calling fetch() with maxResponseSize: 0 intending 'unlimited', maxResponseSize: -1, or a NaN/Infinity value computed from config; passing a string from an env var without Number() conversion.
Common situations: Users setting 0 or -1 as 'no limit' sentinels in coc settings; config parsers returning strings; arithmetic on undefined producing NaN.
Understand the failure class
Background: Invalid option value errors: "must be one of", "is not a valid", and "only allows" failures explained — this error's family across 23 libraries.
Related errors
- Invalid action ${action}
- ${name} must be a positive finite number
- Not valid protocol with ${urlInput}, should be http: or http
- name and doComplete required for createSource
- Required root pattern not resolved.
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/fedae4493df0e263.
Report an issue: GitHub.