{"record":{"id":"9e05fa148128ce87","repo":"withastro/astro","slug":"renderundefinedentryerror","errorCode":"RenderUndefinedEntryError","errorMessage":"Attempted to render an undefined content collection entry.","messagePattern":"Attempted to render an undefined content collection entry\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/runtime.ts","lineNumber":626,"sourceCode":"\t\tconst resolved = resolveImageAtPath(src, fileName, imageAssetMap);\n\t\tif (resolved !== undefined) {\n\t\t\tresult = setAtPathCopying(result, path, resolved);\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function resolveEntryData<T extends Record<string, unknown>>(\n\tentry: DataEntry<T>,\n\timageAssetMap?: Map<string, ImageMetadata>,\n): T {\n\treturn updateImageReferencesInData(entry.data, entry.filePath, imageAssetMap, entry.imageImports);\n}\n\nexport function createRenderEntry({ logger }: { logger: AstroLogger }) {\n\treturn async function renderEntry(entry: DataEntry) {\n\t\tif (!entry) {\n\t\t\tthrow new AstroError(AstroErrorData.RenderUndefinedEntryError);\n\t\t}\n\t\trecordContentEntryRender(entry.filePath);\n\n\t\tif (entry.deferredRender) {\n\t\t\ttry {\n\t\t\t\t// @ts-expect-error\tvirtual module\n\t\t\t\tconst { default: contentModules } = await import('astro:content-module-imports');\n\t\t\t\tconst renderEntryImport = contentModules.get(entry.filePath);\n\t\t\t\treturn render({\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tid: entry.id,\n\t\t\t\t\trenderEntryImport,\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tlogger.error('content', `${e}`);\n\t\t\t}\n\t\t}\n","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/content/runtime.ts#L608-L644","documentation":"renderEntry() backs the public render(entry) from astro:content and throws this error when it receives a falsy entry. getEntry and getCollection lookups return undefined for ids/slugs that do not exist, so rendering without a check turns a missing entry into this explicit error rather than a cryptic crash inside the renderer.","triggerScenarios":"Calling render(entry) where entry came from getEntry('blog', id) and no entry with that id/slug exists; dynamic routes ([...slug].astro) where params.slug matches no entry; entries removed or renamed between data sync and render.","commonSituations":"Dynamic routes without a getStaticPaths guard; typo'd slug from a URL parameter; content deleted during a CMS migration while pages still reference it; code assuming getEntry throws on miss instead of returning undefined.","solutions":["Check the entry before rendering and return a 404 or redirect: if (!post) return Astro.redirect('/404').","Verify the identifier you pass matches how entries are keyed: id for data entries, slug for content entries.","For dynamic routes, generate params from getCollection()/getStaticPaths so only existing entries render."],"exampleFix":"// before\nconst post = await getEntry('blog', params.slug);\nconst { Content } = await render(post);\n\n// after\nconst post = await getEntry('blog', params.slug);\nif (!post) return Astro.redirect('/404');\nconst { Content } = await render(post);","handlingStrategy":"type-guard","validationCode":"// Always resolve and check before rendering\nconst post = params.slug ? await getEntry('blog', params.slug) : undefined;\nif (!post) return Astro.redirect('/404');\nconst { Content } = await render(post);","typeGuard":"import type { CollectionEntry } from 'astro:content';\n\nfunction isRenderableEntry<E>(entry: E | undefined | null): entry is E {\n  return entry != null;\n}\n\n// usage\nif (isRenderableEntry(post)) await render(post);","tryCatchPattern":null,"preventionTips":["Treat every getEntry/getEntryBySlug call as possibly returning undefined.","In dynamic routes, derive params from the collection itself via getStaticPaths so missing entries cannot reach render().","Enable strict TS settings (strictNullChecks) so undefined results surface at compile time."],"tags":["content-collections","render","null-safety","dynamic-routes"],"backgroundTag":"undefined-is-not-an-object","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-09-09T03:35:40.650Z","contentChangedAt":"2026-09-09T03:35:40.650Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}