{"record":{"id":"c138c452861e5ada","repo":"gatsbyjs/gatsby","slug":"reporter-prefix-error-in-custom-page-filter-if","errorCode":null,"errorMessage":"${REPORTER_PREFIX} Error in custom page filter.\nIf you've customized your excludes you may need to provide a custom \"filterPages\" function in your config.\nhttps://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference\n","messagePattern":"(.+?) Error in custom page filter\\.\nIf you've customized your excludes you may need to provide a custom \"filterPages\" function in your config\\.\nhttps://www\\.gatsbyjs\\.com/plugins/gatsby-plugin-sitemap/#api-reference\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sitemap/src/internals.js","lineNumber":199,"sourceCode":"          page\n        )}`\n      )\n    }\n\n    // If page is marked to be excluded via defaults there's no need to check page for custom excludes\n    if (defaultFilterMatches) {\n      return !defaultFilterMatches\n    }\n\n    const customFilterMatches = excludes.some(exclude => {\n      try {\n        return filterPages(page, exclude, {\n          minimatch,\n          withoutTrailingSlash,\n          resolvePagePath,\n        })\n      } catch {\n        throw new Error(\n          `${REPORTER_PREFIX} Error in custom page filter.\nIf you've customized your excludes you may need to provide a custom \"filterPages\" function in your config.\nhttps://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference\n`\n        )\n      }\n    })\n\n    if (customFilterMatches) {\n      messages.push(\n        `${REPORTER_PREFIX} Custom filtering excluded page ${resolvePagePath(\n          page\n        )}`\n      )\n    }\n\n    return !(defaultFilterMatches || customFilterMatches)\n  })","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sitemap/src/internals.js#L181-L217","documentation":"Thrown by gatsby-plugin-sitemap when the user-provided custom filterPages function (or its default) throws while matching a page against a custom exclude pattern. This covers the `excludes` array from the plugin config, distinct from the built-in default excludes. The message guides the user to supply a custom filterPages function because their excludes patterns likely contain values the default matcher cannot handle.","triggerScenarios":"The excludes.some() loop calls the configured filterPages() with each exclude entry; if an exclude is not a string/glob pattern that minimatch can process, or if the page path is malformed, the inner call throws and is caught by the bare catch which rethrows this message.","commonSituations":"A user configures `excludes` with a regex object or non-string value instead of a glob string, uses a glob pattern minimatch rejects, or passes excludes entries that depend on page fields that don't exist.","solutions":["Ensure every entry in the sitemap plugin's `excludes` option is a glob string (e.g., '/admin/*'), not a RegExp or object.","Provide a custom `filterPages` function in gatsby-config.js under the sitemap plugin options to handle non-standard exclude logic.","Verify minimatch syntax — use forward-slash absolute paths starting with '/' relative to the site root.","Check the plugin options reference at the URL in the error for the expected filterPages signature."],"exampleFix":"// before\n{\n  resolve: 'gatsby-plugin-sitemap',\n  options: { excludes: [/^\\/admin/] }\n}\n// after\n{\n  resolve: 'gatsby-plugin-sitemap',\n  options: { excludes: ['/admin/*'] }\n}","handlingStrategy":"validation","validationCode":"// Validate excludes config before build\nconst validExcludes = pluginOptions.excludes.filter(e => typeof e === 'string')\nif (validExcludes.length !== pluginOptions.excludes.length) {\n  throw new Error('All sitemap excludes must be glob strings')\n}","typeGuard":"const isGlobString = (val: unknown): val is string =>\n  typeof val === 'string' && val.length > 0","tryCatchPattern":null,"preventionTips":["Always use glob string patterns (not RegExp) in the excludes option.","Provide a custom filterPages function when your exclude logic is non-standard.","Test exclude patterns against your actual page list before deploying."],"tags":["gatsby","sitemap","configuration","minimatch","filtering"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}