-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[@astrojs/cloudflare] Prerenderer swallows error details from workerd, returns opaque 500 #15860
Description
Description
When using injectRoute() in an Astro integration with the @astrojs/cloudflare adapter, the prerenderer fails with a generic 500: Internal Server Error message that provides no actionable information:
prerendering static routes
Failed to get static paths from the Cloudflare prerender server (500: Internal Server Error).
This is likely a bug in @astrojs/cloudflare.
The actual error from the workerd environment (e.g., GetStaticPathsRequired) is available in the response body but is never read or displayed.
Reproduction
- Create an Astro project with
@astrojs/cloudflareadapter - Create an integration that uses
injectRoute()with a dynamic route:
// src/integrations/my-router.ts
import type { AstroIntegration } from 'astro'
export default function myRouter(): AstroIntegration {
return {
name: 'my-router',
hooks: {
'astro:config:setup': ({ injectRoute }) => {
injectRoute({
pattern: '/en/blog/[...slug]',
entrypoint: './src/views/blog.astro',
// missing prerender: false — defaults to prerendered
})
},
},
}
}- The view file has a
[...slug]dynamic segment but nogetStaticPaths()export (since the intent is SSR) - Run
astro build
Expected: A clear error like GetStaticPathsRequired: getStaticPaths() function is required for dynamic routes
Actual: Failed to get static paths from the Cloudflare prerender server (500: Internal Server Error)
Root cause
In dist/prerenderer.js, the getStaticPaths() method checks response.ok but discards the response body:
if (!response.ok) {
throw new Error(
`Failed to get static paths from the Cloudflare prerender server (${response.status}: ${response.statusText}).`
);
}The workerd server at /__astro_static_paths returns the actual error in the body, but it's never read.
Suggested fix
Read the response body and include it in the error message:
if (!response.ok) {
const body = await response.text();
throw new Error(
`Failed to get static paths from the Cloudflare prerender server (${response.status}: ${response.statusText}).\n${body}`
);
}The same pattern should be applied to the render() and collectStaticImages() methods for consistency.
Additional context
@astrojs/cloudflareversion: 13.0.2astroversion: 6.0.1- The fix above is a one-liner but it saves significant debugging time. I spent a while thinking this was a bug in
injectRoutewhen the actual cause was a missingprerender: falseon a dynamic route.
Optional DX improvement
When injectRoute() is called with a pattern containing dynamic segments (like [...slug]) and prerender is not explicitly set, it might be helpful to either:
- Default dynamic injected routes to
prerender: false - Or emit a warning suggesting the developer set
prerenderexplicitly