{"record":{"id":"8e5b36b9bb6b9137","repo":"getzola/zola","slug":"could-not-build-not-found-response","errorCode":null,"errorMessage":"Could not build Not Found response","messagePattern":"Could not build Not Found response","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/serve.rs","lineNumber":391,"sourceCode":"    match err.kind() {\n        std::io::ErrorKind::NotFound => not_found(),\n        std::io::ErrorKind::PermissionDenied => {\n            Response::builder().status(StatusCode::FORBIDDEN).body(Body::empty()).unwrap()\n        }\n        _ => panic!(\"{}\", err),\n    }\n}\n\nfn not_found() -> Response {\n    let not_found_path = RelativePath::new(\"404.html\");\n    let content = SITE_CONTENT.read().unwrap().get(not_found_path).cloned();\n\n    if let Some(body) = content {\n        return Response::builder()\n            .header(header::CONTENT_TYPE, \"text/html\")\n            .status(StatusCode::NOT_FOUND)\n            .body(Body::from(body))\n            .expect(\"Could not build Not Found response\");\n    }\n\n    // Use a plain text response when we can't find the body of the 404\n    Response::builder()\n        .header(header::CONTENT_TYPE, \"text/plain\")\n        .status(StatusCode::NOT_FOUND)\n        .body(Body::from(NOT_FOUND_TEXT))\n        .expect(\"Could not build Not Found response\")\n}\n\nfn rebuild_done_handling(\n    broadcaster: &broadcast::Sender<String>,\n    res: Result<()>,\n    reload_path: &str,\n) {\n    match res {\n        Ok(_) => {\n            clear_serve_error();","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/src/cmd/serve.rs#L373-L409","documentation":"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.","triggerScenarios":"Thrown at src/cmd/serve.rs:391 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}