{"record":{"id":"b015384c9cade04b","repo":"denoland/deno","slug":"err-invalid-arg-type","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"${name}[${i}]\" argument must be of type string","messagePattern":"The \"(.+?)\\[(.+?)\\]\" argument must be of type string","errorType":"validation","errorClass":"NodeTypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_fs/_fs_glob.ts","lineNumber":204,"sourceCode":"\nfunction getRealpathStringSync(path) {\n  try {\n    return op_require_real_path(path);\n  } catch {\n    return null;\n  }\n}\n\n/**\n * @callback validateStringArrayOrFunction\n * @param {*} value\n * @param {string} name\n */\nconst validateStringArrayOrFunction = hideStackFrames((value, name) => {\n  if (ArrayIsArray(value)) {\n    for (let i = 0; i < value.length; ++i) {\n      if (typeof value[i] !== \"string\") {\n        throw new ERR_INVALID_ARG_TYPE(`${name}[${i}]`, \"string\", value[i]);\n      }\n    }\n    return;\n  }\n  if (typeof value !== \"function\") {\n    throw new ERR_INVALID_ARG_TYPE(name, [\"string[]\", \"function\"], value);\n  }\n});\n\n/**\n * @param {string} pattern\n * @param {options} options\n * @returns {Minimatch}\n */\nfunction createMatcher(pattern, options = kEmptyObject) {\n  const opts = {\n    __proto__: null,\n    nocase: isWindows || isMacOS,","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_fs/_fs_glob.ts#L186-L222","documentation":"In fs.glob (and fs.promises.glob), options.exclude may be either an array of glob-pattern strings or a predicate function. validateStringArrayOrFunction checks each array element; a non-string element (number, null, undefined, RegExp) throws ERR_INVALID_ARG_TYPE naming options.exclude[i].","triggerScenarios":"fs.glob('**/*.ts', { exclude: ['node_modules', /build/] }); exclude: ['dist', 42]; arrays built from config where some entries are undefined.","commonSituations":"Mixing RegExp filters into exclude (it expects glob strings); assembling exclude lists from heterogeneous config; spreading optional arrays that contain holes or nulls.","solutions":["Keep every exclude entry a string glob: ['dist/**', 'coverage/**']","Convert RegExp filters to globs, or use the function form: exclude: (p) => re.test(p)","Sanitize before passing: exclude.filter((x) => typeof x === 'string')"],"exampleFix":"// before\nfs.glob(\"**/*.ts\", { exclude: [\"node_modules\", /vendor/] }, cb);\n\n// after\nfs.glob(\"**/*.ts\", { exclude: [\"node_modules\", \"vendor/**\"] }, cb);\n// or the predicate form:\nfs.glob(\"**/*.ts\", { exclude: (p) => /vendor/.test(p) }, cb);","handlingStrategy":"type-guard","validationCode":"function normalizeExclude(v: unknown): string[] | ((p: string) => boolean) {\n  if (typeof v === \"function\") return v;\n  if (Array.isArray(v)) {\n    const strs = v.filter((x): x is string => typeof x === \"string\");\n    if (strs.length !== v.length) {\n      throw new Error(\n        \"fs.glob options.exclude must be an array of glob strings or a function; found non-string entries - convert RegExp filters to the function form\",\n      );\n    }\n    return strs;\n  }\n  throw new Error(\"options.exclude must be string[] or function\");\n}","typeGuard":"function isStringArrayOrFunction(v: unknown): v is string[] | ((p: string) => boolean) {\n  if (typeof v === \"function\") return true;\n  return Array.isArray(v) && v.every((x) => typeof x === \"string\");\n}","tryCatchPattern":null,"preventionTips":["Express exclusion filters as glob strings, or as one predicate function for RegExp logic","Type options.exclude as string[] in TypeScript so numbers/nulls are rejected at compile time","Filter config-derived arrays to strings before passing them into fs.glob"],"tags":["fs","glob","node-compat","validation","types"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}