{"record":{"id":"ca288164d70ca70a","repo":"nodejs/node","slug":"expected-name-to-be-an-array-or-undefined-got","errorCode":null,"errorMessage":"expected ${name} to be an array or undefined, got ${typeof origins}","messagePattern":"expected (.+?) to be an array or undefined, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/interceptor/cache.js","lineNumber":20,"sourceCode":"\nconst assert = require('node:assert')\nconst { Readable } = require('node:stream')\nconst util = require('../core/util')\nconst CacheHandler = require('../handler/cache-handler')\nconst MemoryCacheStore = require('../cache/memory-cache-store')\nconst CacheRevalidationHandler = require('../handler/cache-revalidation-handler')\nconst { assertCacheStore, assertCacheMethods, makeCacheKey, normalizeHeaders, parseCacheControlHeader, isInvalidOrWildcardVaryHeader } = require('../util/cache.js')\nconst { AbortError } = require('../core/errors.js')\nconst { parseHttpDate } = require('../util/date.js')\n\n/**\n * @param {(string | RegExp)[] | undefined} origins\n * @param {string} name\n */\nfunction assertCacheOrigins (origins, name) {\n  if (origins === undefined) return\n  if (!Array.isArray(origins)) {\n    throw new TypeError(`expected ${name} to be an array or undefined, got ${typeof origins}`)\n  }\n  for (let i = 0; i < origins.length; i++) {\n    const origin = origins[i]\n    if (typeof origin !== 'string' && !(origin instanceof RegExp)) {\n      throw new TypeError(`expected ${name}[${i}] to be a string or RegExp, got ${typeof origin}`)\n    }\n  }\n}\n\nconst nop = () => {}\n\nfunction trimOWS (value) {\n  return value.replace(/^[\\t ]+|[\\t ]+$/g, '')\n}\n\nfunction arrayIncludes (array, value) {\n  for (let i = 0; i < array.length; i++) {\n    if (array[i] === value) {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/interceptor/cache.js#L2-L38","documentation":"Thrown by assertCacheOrigins in the cache() interceptor factory. The origins option (a whitelist of origins eligible for caching) must be undefined (cache all origins) or an array of strings/RegExps. Passing any other type (a single string, an object, a number, a Set) is rejected.","triggerScenarios":"Calling interceptors.cache({ origins: ... }) with origins as a string ('https://a.com'), a Set, an object map, or any non-array value.","commonSituations":"Configuring the cache interceptor from a config file that used a single string or a Set; copy-pasting an example that used a different shape; TypeScript where the type was widened.","solutions":["Pass origins as an array: ['https://a.com', /https:\\/\\/.*\\.internal/], or omit it to cache all origins.","Convert single strings: ['https://a.com']; convert Sets: Array.from(set).","Validate the option at the config boundary before composing the interceptor."],"exampleFix":"// before\nclient.compose(interceptors.cache({ origins: 'https://api.example.com' }))\n\n// after\nclient.compose(interceptors.cache({ origins: ['https://api.example.com'] }))","handlingStrategy":"validation","validationCode":"function normalizeOrigins(v) {\n  if (v == null) return undefined\n  return Array.isArray(v) ? v : [v]\n}","typeGuard":"function isOrigins(v) { return v == null || (Array.isArray(v) && v.every(o => typeof o === 'string' || o instanceof RegExp)) }","tryCatchPattern":"try { client.compose(interceptors.cache({ origins })) } catch (e) { if (e instanceof TypeError && /to be an array/.test(e.message)) { client.compose(interceptors.cache({ origins: Array.isArray(origins) ? origins : [origins] })) } else throw e }","preventionTips":["Always pass origins as an array of strings/RegExps.","Omit the option to cache all origins.","Convert single strings/Sets at the config boundary."],"tags":["undici","http","cache","interceptor","configuration","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}