{"record":{"id":"8ac8352de68db2e3","repo":"gatsbyjs/gatsby","slug":"invalid-options-passed-to-page-filter-function","errorCode":null,"errorMessage":"Invalid options passed to page Filter function","messagePattern":"Invalid options passed to page Filter function","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/internals.js","lineNumber":159,"sourceCode":"  }\n}\n\nconst defaultExcludes = [\n  `/dev-404-page`,\n  `/404`,\n  `/404.html`,\n  `/offline-plugin-app-shell-fallback`,\n]\n\nexport function pageFilter({ allPages, filterPages, excludes }) {\n  const messages = []\n\n  if (\n    !Array.isArray(allPages) ||\n    typeof filterPages !== `function` ||\n    !Array.isArray(excludes)\n  ) {\n    throw new Error(`Invalid options passed to page Filter function`)\n  }\n\n  // TODO we should optimize these loops\n  const filteredPages = allPages.filter(page => {\n    const defaultFilterMatches = defaultExcludes.some(exclude => {\n      try {\n        const doesMatch = defaultFilterPages(page, exclude, {\n          minimatch,\n          withoutTrailingSlash,\n          resolvePagePath,\n        })\n\n        return doesMatch\n      } catch {\n        throw new Error(`${REPORTER_PREFIX} Error in default page filter`)\n      }\n    })\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/internals.js#L141-L177","documentation":"pageFilter is the top-level sitemap filtering entry point. It requires allPages to be an array, filterPages to be a function, and excludes to be an array. If any of these contracts is violated, it throws 'Invalid options passed to page Filter function'. This is almost always a plugin-internal invocation error rather than direct user input, because the plugin assembles these from its options.","triggerScenarios":"Plugin option misconfiguration: options.filterPages set to a non-function (string, object); options.exclude set to a non-array (string, object); or the Gatsby pages collection not being an array due to an upstream node issue. Also reachable if a custom integration calls pageFilter directly with wrong shapes.","commonSituations":"Setting options.filterPages to a glob string by mistake; passing options.exclude as a single string instead of an array; version mismatch between gatsby-plugin-sitemap and gatsby core where the pages shape changed; plugin loaded twice with conflicting configs.","solutions":["Ensure options.exclude is an array of strings: exclude: ['/secret'].","Ensure options.filterPages, if provided, is a function: filterPages: (page, excludes) => boolean.","Update gatsby-plugin-sitemap to the latest version compatible with your gatsby.","If the error persists, check that no other plugin is mangling the pages array in onCreatePage/createsPages."],"exampleFix":"// before\n{\n  resolve: `gatsby-plugin-sitemap`,\n  options: { exclude: `/secret`, filterPages: `glob` }\n}\n\n// after\n{\n  resolve: `gatsby-plugin-sitemap`,\n  options: {\n    exclude: [`/secret`],\n    filterPages: (page, excludedRoutes) => !excludedRoutes.includes(page.path)\n  }\n}","handlingStrategy":"type-guard","validationCode":"function validateSitemapOptions({ allPages, filterPages, excludes }) {\n  if (!Array.isArray(allPages)) throw new Error('allPages must be an array');\n  if (typeof filterPages !== 'function') throw new Error('filterPages must be a function');\n  if (!Array.isArray(excludes)) throw new Error('excludes must be an array');\n}","typeGuard":"function isValidPageFilterArgs({ allPages, filterPages, excludes }) {\n  return Array.isArray(allPages) &&\n    typeof filterPages === 'function' &&\n    Array.isArray(excludes);\n}","tryCatchPattern":null,"preventionTips":["Keep gatsby-plugin-sitemap and gatsby core versions compatible.","Type-check plugin options (exclude: string[], filterPages?: function).","Avoid loading the plugin twice with conflicting configurations."],"tags":["gatsby-plugin-sitemap","config","validation","filter"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}