{"record":{"id":"b7692e867a334b70","repo":"payloadcms/payload","slug":"the-collection-with-slug-string-collectionslug-b7692e","errorCode":null,"errorMessage":"The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.","messagePattern":"The collection with slug (.+?) can't be found\\. Duplicate Operation\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/collections/operations/local/duplicate.ts","lineNumber":115,"sourceCode":"): Promise<TransformCollectionWithSelect<TSlug, TSelect>> {\n  const {\n    id,\n    collection: collectionSlug,\n    data,\n    depth,\n    disableTransaction,\n    draft,\n    overrideAccess = true,\n    populate,\n    select,\n    selectedLocales,\n    showHiddenFields,\n  } = options\n\n  const collection = payload.collections[collectionSlug]\n\n  if (!collection) {\n    throw new APIError(\n      `The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`,\n    )\n  }\n\n  if (collection.config.disableDuplicate === true) {\n    throw new APIError(\n      `The collection with slug ${String(collectionSlug)} cannot be duplicated.`,\n      400,\n    )\n  }\n\n  const req = await createLocalReq(options as CreateLocalReqOptions, payload)\n\n  return duplicateOperation<TSlug, TSelect>({\n    id,\n    collection,\n    data,\n    depth,","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/local/duplicate.ts#L97-L133","documentation":"Thrown by the Local API `duplicate` wrapper in packages/payload/src/collections/operations/local/duplicate.ts:115 when `payload.duplicate({ collection, id })` targets a slug not registered in `payload.collections`. Defaults to HTTP 500. It is the first of two guards in duplicateLocal — the second (error 145) checks `disableDuplicate`.","triggerScenarios":"Calling `payload.duplicate({ collection: 'media-item', id })` when the real slug is `'media'`; duplicating from a generic action handler that receives an unvalidated slug; calling duplicate before `payload.init()` registers collections.","commonSituations":"Slug typo or stale constant; collection removed; plugin conditionally registering the collection not loaded; `as CollectionSlug` cast on a dynamic value.","solutions":["Confirm the slug matches the collection config exactly.","Validate dynamic slugs against `Object.keys(payload.collections)` before duplicating.","Ensure `payload.init()` finished and the collection is registered.","Remove `as CollectionSlug` casts so the compiler catches bad slugs."],"exampleFix":"// before\nawait payload.duplicate({ collection: 'product' as CollectionSlug, id }) // slug is 'products'\n\n// after\nawait payload.duplicate({ collection: 'products', id })","handlingStrategy":"validation","validationCode":"function assertCollectionSlug(payload: Payload, slug: string): void {\n  if (!(slug in payload.collections)) {\n    throw new Error(`Unknown collection slug '${slug}'`)\n  }\n}\nassertCollectionSlug(payload, 'products')\nawait payload.duplicate({ collection: 'products', id })","typeGuard":"const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>\n  slug in (payload.collections as Record<string, unknown>)\n\nif (slugIsRegistered(payload, slug)) {\n  await payload.duplicate({ collection: slug, id })\n}","tryCatchPattern":"try {\n  await payload.duplicate({ collection: slug, id })\n} catch (err) {\n  if (err instanceof APIError && /Duplicate Operation/.test(err.message)) {\n    // unknown slug — correct it\n  } else throw err\n}","preventionTips":["Validate slugs from admin/UI actions against payload.collections.","Keep slug constants centralized.","Avoid `as CollectionSlug` casts on runtime strings."],"tags":["local-api","collection","slug","duplicate","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}