{"record":{"id":"b9af059639f39fe2","repo":"payloadcms/payload","slug":"the-global-with-slug-string-globalslug-can-t-b","errorCode":null,"errorMessage":"The global with slug ${String(globalSlug)} can't be found. Count Global Versions Operation.","messagePattern":"The global with slug (.+?) can't be found\\. Count Global Versions Operation\\.","errorType":"exception","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/globals/operations/local/countVersions.ts","lineNumber":59,"sourceCode":"   * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n   */\n  user?: null | User\n  /**\n   * A filter [query](https://payloadcms.com/docs/queries/overview)\n   */\n  where?: Where\n}\n\nexport async function countGlobalVersionsLocal<TSlug extends GlobalSlug>(\n  payload: Payload,\n  options: CountGlobalVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n  const { disableErrors, global: globalSlug, overrideAccess = true, where } = options\n\n  const global = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n  if (!global) {\n    throw new APIError(\n      `The global with slug ${String(globalSlug)} can't be found. Count Global Versions Operation.`,\n    )\n  }\n\n  return countGlobalVersionsOperation<TSlug>({\n    disableErrors,\n    global,\n    overrideAccess,\n    req: await createLocalReq(options as CreateLocalReqOptions, payload),\n    where,\n  })\n}\n","sourceCodeStart":41,"sourceCodeEnd":72,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/globals/operations/local/countVersions.ts#L41-L72","documentation":"Thrown by countGlobalVersionsLocal when no global in payload.globals.config matches the supplied slug. It is a guard at the entry of the Local API before any DB query runs, so a bad slug fails fast. Surfaced as an APIError (HTTP 400/500 depending on context).","triggerScenarios":"Calling payload.countGlobalVersions({ global: 'nonexistent' }) or a slug that has a typo/case mismatch. Also when the global was renamed but the caller still uses the old slug.","commonSituations":"Refactoring a global slug and forgetting to update a call site; copy-paste between projects with different global names; calling the Local API during a migration before Payload has registered the global.","solutions":["Check payload.globals.config.some(g => g.slug === slug) before calling.","Use the typed GlobalSlug union so the compiler rejects unknown slugs.","Grep for the old slug after any rename and update all references.","Ensure Payload has finished init (await payload.init()) before invoking Local API methods."],"exampleFix":"// before\nconst { totalDocs } = await payload.countGlobalVersions({ global: 'brading' })\n\n// after\nconst slug = 'branding' as const\nif (!payload.globals.config.some(g => g.slug === slug)) {\n  throw new Error(`Unknown global slug: ${slug}`)\n}\nconst { totalDocs } = await payload.countGlobalVersions({ global: slug })","handlingStrategy":"validation","validationCode":"if (!payload.globals.config.some((g) => g.slug === slug)) {\n  throw new Error(`Unknown global: ${slug}`)\n}","typeGuard":"const knownGlobals: ReadonlySet<string> = new Set(\n  payload.globals.config.map((g) => g.slug),\n)\nfunction isKnownGlobal(slug: string): slug is GlobalSlug {\n  return knownGlobals.has(slug)\n}","tryCatchPattern":"try {\n  await payload.countGlobalVersions({ global: slug })\n} catch (err) {\n  if (err instanceof APIError && /can't be found/.test(err.message)) return 0\n  throw err\n}","preventionTips":["Derive global slugs from the typed GlobalSlug union, not free strings.","Grep for the old slug whenever a global is renamed."],"tags":["globals","local-api","config","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}