{"record":{"id":"fedae4493df0e263","repo":"neoclide/coc.nvim","slug":"maxresponsesize-must-be-a-positive-finite-number","errorCode":null,"errorMessage":"maxResponseSize must be a positive finite number","messagePattern":"maxResponseSize must be a positive finite number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/model/fetch.ts","lineNumber":192,"sourceCode":"    headers: {\n      'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)',\n      'Accept-Encoding': 'gzip, deflate',\n      ...(options.headers ?? {})\n    }\n  }\n  if (dataType == 'object') {\n    opts.headers['Content-Type'] = 'application/json'\n  } else if (dataType == 'string') {\n    opts.headers['Content-Type'] = 'text/plain'\n  }\n  if (proxyOptions.proxyAuthorization) opts.headers['Proxy-Authorization'] = proxyOptions.proxyAuthorization\n  if (proxyOptions.proxyCA) opts.ca = fs.readFileSync(proxyOptions.proxyCA)\n  if (options.user) opts.auth = options.user + ':' + (toText(options.password))\n  if (url.username) opts.auth = url.username + ':' + (toText(url.password))\n  if (options.timeout) opts.timeout = options.timeout\n  if (options.buffer) opts.buffer = true\n  let maxResponseSize = options.maxResponseSize ?? DEFAULT_MAX_RESPONSE_SIZE\n  if (!Number.isFinite(maxResponseSize) || maxResponseSize <= 0) throw new Error('maxResponseSize must be a positive finite number')\n  opts.maxResponseSize = maxResponseSize\n  return opts\n}\n\n/**\n * Extract and validate the charset parameter of a Content-Type header.\n * Handles quoted values (charset=\"utf-8\") and trailing parameters\n * (charset=utf-8; format=flowed); throws for unsupported encodings.\n */\nfunction parseCharset(contentType: string): BufferEncoding {\n  let match = /;\\s*charset\\s*=\\s*\"?([^\";\\s]+)\"?/i.exec(contentType)\n  let encoding = match ? match[1] : 'utf8'\n  let lower = encoding.toLowerCase()\n  if (lower === 'iso-8859-1' || lower === 'latin-1') encoding = 'latin1'\n  else if (lower === 'utf-16' || lower === 'utf-16le' || lower === 'ucs-2' || lower === 'ucs2') encoding = 'utf16le'\n  else if (lower === 'us-ascii') encoding = 'ascii'\n  if (!Buffer.isEncoding(encoding)) {\n    throw new Error(`Unsupported charset: ${encoding}`)","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/model/fetch.ts#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"Users setting 0 or -1 as 'no limit' sentinels in coc settings; config parsers returning strings; arithmetic on undefined producing NaN.","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."],"exampleFix":"// before\nfetch(url, { maxResponseSize: 0 })\n// after\nfetch(url, { maxResponseSize: 50 * 1024 * 1024 }) // or omit the option","handlingStrategy":"validation","validationCode":"function validMaxResponseSize(v) {\n  if (v === undefined) return true\n  return Number.isFinite(v) && v > 0\n}\nif (!validMaxResponseSize(opts.maxResponseSize))\n  throw new Error('maxResponseSize must be a positive finite number or undefined')","typeGuard":"function isPositiveFinite(v: unknown): v is number { return typeof v === 'number' && Number.isFinite(v) && v > 0 }","tryCatchPattern":"try {\n  return await fetch(url, { maxResponseSize })\n} catch (e) {\n  if (/maxResponseSize must be/.test(e.message)) return fetch(url) // fall back to default limit\n  throw e\n}","preventionTips":["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."],"tags":["validation","network","configuration"],"backgroundTag":"invalid-option-value","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}