{"record":{"id":"7826b9d1d936a53d","repo":"getzola/zola","slug":"could-not-read-because-of-error","errorCode":null,"errorMessage":"Could not read `{}` because of error: {}","messagePattern":"Could not read `(.+?)` because of error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/init.rs","lineNumber":44,"sourceCode":"\"#;\n\n// canonicalize(path) function on windows system returns a path with UNC.\n// Example: \\\\?\\C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\new_project\n// More details on Universal Naming Convention (UNC):\n// https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention\n// So the following const will be used to remove the network part of the UNC to display users a more common\n// path on windows systems.\n// This is a workaround until this issue https://github.com/rust-lang/rust/issues/42869 was fixed.\nconst LOCAL_UNC: &str = \"\\\\\\\\?\\\\\";\n\n// Given a path, return true if it is a directory and it doesn't have any\n// non-hidden files, otherwise return false (path is assumed to exist)\npub fn is_directory_quasi_empty(path: &Path) -> Result<bool> {\n    if path.is_dir() {\n        let mut entries = match path.read_dir() {\n            Ok(entries) => entries,\n            Err(e) => {\n                bail!(\"Could not read `{}` because of error: {}\", path.to_string_lossy(), e);\n            }\n        };\n        // If any entry raises an error or isn't hidden (i.e. starts with `.`), we raise an error\n        if entries.any(|x| match x {\n            Ok(file) => !file\n                .file_name()\n                .to_str()\n                .expect(\"Could not convert filename to &str\")\n                .starts_with('.'),\n            Err(_) => true,\n        }) {\n            return Ok(false);\n        }\n        return Ok(true);\n    }\n\n    Ok(false)\n}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/src/cmd/init.rs#L26-L62","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$ zola init /var/www   # Permission denied\n// after\n$ sudo chown $USER /var/www && zola init /var/www","handlingStrategy":"try-catch","validationCode":"fn dir_readable(path: &Path) -> bool { path.is_dir() && path.read_dir().is_ok() }","typeGuard":null,"tryCatchPattern":"match is_directory_quasi_empty(path) {\n    Ok(empty) => proceed(empty),\n    Err(e) if e.to_string().contains(\"Could not read\") => {\n        eprintln!(\"fix permissions on {}: {e}\", path.display());\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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"],"tags":["rust","filesystem","permissions","zola-init"],"backgroundTag":"permission-denied","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"}