actix/actix-web · warning · io::Error
No such file
Error message
No such file
What it means
io::Error with kind NotFound and message 'No such file' (service.rs:289-290) is the fallback error in FilesService::call when none of the configured root directories contained the requested path (last_miss stayed None). It is wrapped via handle_err into a response; because the kind is NotFound it renders as HTTP 404. If a default handler is configured it is invoked instead.
Source
Thrown at actix-files/src/service.rs:290
}
Err(err) => return this.handle_err(err, req).await,
}
}
}
if let Some((base, path)) = first_index_listing {
return Ok(this.show_index(req, base, path));
}
if found_unrenderable_dir {
return Ok(ServiceResponse::from_err(
FilesError::IsDirectory,
req.into_parts().0,
));
}
let err = last_miss
.unwrap_or_else(|| io::Error::new(io::ErrorKind::NotFound, "No such file"));
this.handle_err(err, req).await
})
}
}
/// Flate doesn't have an accepted file extension, so it is not included here.
const SUPPORTED_PRECOMPRESSION_ENCODINGS: &[header::ContentEncoding] = &[
header::ContentEncoding::Brotli,
header::ContentEncoding::Gzip,
header::ContentEncoding::Zstd,
header::ContentEncoding::Identity,
];
/// Searches disk for an acceptable alternate encoding of the content at the given path, as
/// preferred by the request's `Accept-Encoding` header. Returns the corresponding `NamedFile` with
/// the most appropriate supported encoding, if any exist.
async fn find_compressed(
req: &ServiceRequest,View on GitHub (pinned to 937960ca67)
Solutions
- Verify the file exists on disk under the directory passed to Files::new.
- Register a default handler via Files::default_handler to serve a custom 404 or fallback route.
- Enable .show_files_listing() or .index_file("index.html") for directory requests if listing/index is desired.
- Check for path-traversal filtering silently rejecting the request (hidden_files=false strips dotfiles).
Example fix
// before: bare Files, raw 404
App::new().service(Files::new("/static", "./assets"))
// after: graceful fallback
App::new().service(
Files::new("/static", "./assets")
.index_file("index.html")
.default_handler(web::to(|| async { HttpResponse::NotFound().body("not found") })),
) Defensive patterns
Strategy: fallback
Validate before calling
// Before relying on a file, optionally check existence (note: TOCTOU).
use std::path::Path;
fn exists(p: &Path) -> bool { p.exists() } Try / catch
// Provide a default handler so 404s render your own page.
App::new().service(
Files::new("/static", "./assets")
.default_handler(web::to(|| async {
HttpResponse::NotFound().body("not found")
})),
) Prevention
- Register a default_handler on Files for custom 404 behaviour.
- Confirm the Files::new root directory and that assets are deployed there.
- Enable index_file / show_files_listing if directory listings are intended.
When it happens
Trigger: A GET/HEAD request to a Files route whose path-on-disk does not exist in any registered directory, and no index file or default fallback matched. Also when the entire route resolves to nothing because the file was deleted.
Common situations: Missing static asset, wrong Files::new root, request for a file that was never deployed, or a typo in the URL. Also when redirect_to_slash / show_index are off and the directory itself has no index.
Related errors
- invalid Range header: invalid syntax
- invalid Range header: range starts after end of content
- Provided path has no filename
- Invalid chunk size line: Invalid Size
- Invalid chunk size line: Size is too big
AI-assisted analysis of actix/actix-web@937960ca67 (2026-08-06).
Data as JSON: /data/errors/86bbefaff1a0b57b.json.
Report an issue: GitHub.