getzola/zola · error
Could not read `{}` because of error: {}
Error message
Could not read `{}` because of error: {} What it means
`is_directory_quasi_empty` checks whether a target path is a directory containing only hidden files before initializing a project. If `path.read_dir()` fails (e.g. permissions or IO error), it bails with the path and OS error. Non-directory paths are not covered by this error — it only fires when the path is a dir but unreadable.
Source
Thrown at src/cmd/init.rs:44
"#;
// canonicalize(path) function on windows system returns a path with UNC.
// Example: \\?\C:\Users\VssAdministrator\AppData\Local\Temp\new_project
// More details on Universal Naming Convention (UNC):
// https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention
// So the following const will be used to remove the network part of the UNC to display users a more common
// path on windows systems.
// This is a workaround until this issue https://github.com/rust-lang/rust/issues/42869 was fixed.
const LOCAL_UNC: &str = "\\\\?\\";
// Given a path, return true if it is a directory and it doesn't have any
// non-hidden files, otherwise return false (path is assumed to exist)
pub fn is_directory_quasi_empty(path: &Path) -> Result<bool> {
if path.is_dir() {
let mut entries = match path.read_dir() {
Ok(entries) => entries,
Err(e) => {
bail!("Could not read `{}` because of error: {}", path.to_string_lossy(), e);
}
};
// If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error
if entries.any(|x| match x {
Ok(file) => !file
.file_name()
.to_str()
.expect("Could not convert filename to &str")
.starts_with('.'),
Err(_) => true,
}) {
return Ok(false);
}
return Ok(true);
}
Ok(false)
}View on GitHub (pinned to 61d3082821)
Solutions
- Fix permissions on the directory so the current user can read it (chmod/chown)
- Run the init command as a user with access to that directory
- Choose a different, accessible directory for the new project
- Check the embedded OS error (e.g. EACCES) to identify the exact cause
Example fix
// before $ zola init /var/www # Permission denied // after $ sudo chown $USER /var/www && zola init /var/www
Defensive patterns
Strategy: try-catch
Validate before calling
fn dir_readable(path: &Path) -> bool { path.is_dir() && path.read_dir().is_ok() } Try / catch
match is_directory_quasi_empty(path) {
Ok(empty) => proceed(empty),
Err(e) if e.to_string().contains("Could not read") => {
eprintln!("fix permissions on {}: {e}", path.display());
}
Err(e) => return Err(e),
} Prevention
- Verify you can `ls` the target directory before running init
- Avoid initializing into root-owned or permission-restricted directories
- Check effective user/mode (EACCES) when running in containers or sandboxes
When it happens
Trigger: Calling `is_directory_quasi_empty` (via `create_new_project` and the init helpers) on a directory the current user cannot list — permission-restricted dir, or an IO error during read_dir iteration.
Common situations: Running `zola init` inside a directory owned by another user or with restrictive mode (e.g. 0700 root-owned); read-only or failing mounts; sandboxed environments denying directory listing.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- Can't watch `{entry}` for changes in folder `{}`. Does it ex
- Can't watch `{entry}`: OS file watch limit reached. Check ho
- Could not convert filename to &str
- could not parse domain `{}` from link
- could not parse domain `{}` from link: `{}`
AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03).
Data as JSON: /api/errors/7826b9d1d936a53d.
Report an issue: GitHub.