payloadcms/payload · error · APIError
The collection with slug ${String(collectionSlug)} can't be
Error message
The collection with slug ${String(collectionSlug)} can't be found. Restore Version Operation. What it means
Thrown by the Local API `restoreVersion` wrapper in packages/payload/src/collections/operations/local/restoreVersion.ts:91 when `payload.restoreVersion({ collection, id })` targets a slug not registered in `payload.collections`. Defaults to HTTP 500. Only meaningful for versioned collections.
Source
Thrown at packages/payload/src/collections/operations/local/restoreVersion.ts:91
export async function restoreVersionLocal<TSlug extends CollectionSlug>(
payload: Payload,
options: Options<TSlug>,
): Promise<DataFromCollectionSlug<TSlug>> {
const {
id,
collection: collectionSlug,
depth,
overrideAccess = true,
populate,
select,
showHiddenFields,
} = options
const collection = payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`The collection with slug ${String(
collectionSlug,
)} can't be found. Restore Version Operation.`,
)
}
const args = {
id,
collection,
depth,
overrideAccess,
payload,
populate,
req: await createLocalReq(options as CreateLocalReqOptions, payload),
select,
showHiddenFields,
}
View on GitHub (pinned to 00c58b35c0)
Solutions
- Confirm the slug matches the collection config exactly.
- Verify the collection still has versions enabled (otherwise there is nothing to restore).
- Check `Object.keys(payload.collections)` at runtime.
- Remove `as CollectionSlug` casts on dynamic strings.
Example fix
// before
await payload.restoreVersion({ collection: 'page', id: versionId }) // slug is 'pages'
// after
await payload.restoreVersion({ collection: 'pages', id: versionId }) Defensive patterns
Strategy: validation
Validate before calling
function assertCollectionSlug(payload: Payload, slug: string): void {
if (!(slug in payload.collections)) {
throw new Error(`Unknown collection slug '${slug}'`)
}
}
assertCollectionSlug(payload, 'pages')
await payload.restoreVersion({ collection: 'pages', id: versionId }) Type guard
const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>
slug in (payload.collections as Record<string, unknown>)
if (slugIsRegistered(payload, slug)) {
await payload.restoreVersion({ collection: slug, id: versionId })
} Try / catch
try {
await payload.restoreVersion({ collection: slug, id: versionId })
} catch (err) {
if (err instanceof APIError && /Restore Version Operation/.test(err.message)) {
// unknown slug — correct it
} else throw err
} Prevention
- Confirm versions are enabled before attempting restore.
- Keep slug constants centralized.
- Avoid `as CollectionSlug` casts on dynamic strings.
When it happens
Trigger: Calling `payload.restoreVersion({ collection: 'page', id: versionId })` with a typo; restoring a version after the collection was renamed or its versions config removed; calling before `payload.init()`.
Common situations: Slug typo; collection renamed; versions disabled; `as CollectionSlug` cast on a dynamic slug.
Related errors
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/38da9c159f10a09c.
Report an issue: GitHub.