getzola/zola · error
Could not build Not Found response
Error message
Could not build Not Found response
What it means
Panics inside not_found() when the fallback Response for a 404 page cannot be constructed. not_found() is invoked by handle_request for any request that misses the static site and by io_error when an accessed file is NotFound. It reads 404.html from the in-memory SITE_CONTENT map and builds an http::Response via Response::builder; the builder's unwrap fires if header values or the status are invalid, so the panic signals an internal programming/state bug rather than a client problem.
Source
Thrown at src/cmd/serve.rs:391
match err.kind() {
std::io::ErrorKind::NotFound => not_found(),
std::io::ErrorKind::PermissionDenied => {
Response::builder().status(StatusCode::FORBIDDEN).body(Body::empty()).unwrap()
}
_ => panic!("{}", err),
}
}
fn not_found() -> Response {
let not_found_path = RelativePath::new("404.html");
let content = SITE_CONTENT.read().unwrap().get(not_found_path).cloned();
if let Some(body) = content {
return Response::builder()
.header(header::CONTENT_TYPE, "text/html")
.status(StatusCode::NOT_FOUND)
.body(Body::from(body))
.expect("Could not build Not Found response");
}
// Use a plain text response when we can't find the body of the 404
Response::builder()
.header(header::CONTENT_TYPE, "text/plain")
.status(StatusCode::NOT_FOUND)
.body(Body::from(NOT_FOUND_TEXT))
.expect("Could not build Not Found response")
}
fn rebuild_done_handling(
broadcaster: &broadcast::Sender<String>,
res: Result<()>,
reload_path: &str,
) {
match res {
Ok(_) => {
clear_serve_error();View on GitHub (pinned to 61d3082821)
Solutions
- Verify the 404.html entry in SITE_CONTENT yields a valid Body and that the Content-Type header value is well-formed
- Replace unwrap() on Response::builder().body() with graceful handling that falls back to a minimal plain-text 404 response
- Log the underlying builder error before terminating so the invalid header/status is identifiable
- Add a unit test that builds the not-found response with an empty and a populated SITE_CONTENT map
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src/cmd/serve.rs:391 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03).
Data as JSON: /api/errors/8e5b36b9bb6b9137.
Report an issue: GitHub.