{"record":{"id":"885a334ce450d1cd","repo":"vercel/next.js","slug":"reading-file","errorCode":null,"errorMessage":"reading file {}","messagePattern":"reading file (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbo-tasks-fs/src/util.rs","lineNumber":20,"sourceCode":"    io::{self, ErrorKind},\n    path::Path,\n};\n\nuse anyhow::{Context, Result, anyhow};\nuse turbo_tasks::ResolvedVc;\nuse url::Url;\n\nuse crate::{DiskFileSystem, FileSystemPath};\n\n/// Converts a disk access `Result<T>` into a `Result<Some<T>>`, where a [`ErrorKind::NotFound`] (or\n/// [`ErrorKind::InvalidFilename`]) error results in a [`None`] value. This is purely to reduce\n/// boilerplate code comparing [`ErrorKind::NotFound`] errors against all other errors.\npub fn extract_disk_access<T>(value: io::Result<T>, path: &Path) -> Result<Option<T>> {\n    match value {\n        Ok(v) => Ok(Some(v)),\n        Err(e) if matches!(e.kind(), ErrorKind::NotFound | ErrorKind::InvalidFilename) => Ok(None),\n        // ast-grep-ignore: no-context-format\n        Err(e) => Err(anyhow!(e).context(format!(\"reading file {}\", path.display()))),\n    }\n}\n\npub async fn uri_from_file(root: FileSystemPath, path: Option<&str>) -> Result<String> {\n    let root_fs = root.fs;\n    let root_fs = &*ResolvedVc::try_downcast_type::<DiskFileSystem>(root_fs)\n        .context(\"Expected root to have a DiskFileSystem\")?\n        .await?;\n\n    let path = match path {\n        Some(path) => root.join(path)?,\n        None => root,\n    };\n\n    // `to_sys_path` returns a win32 path on Windows. `Url::from_file_path` can also handle\n    // verbatim (`\\\\?\\`-prefixed) disk and UNC paths, in case that conversion failed.\n    let sys_path = root_fs.to_sys_path(&path);\n    Ok(String::from(Url::from_file_path(&sys_path).map_err(","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbo-tasks-fs/src/util.rs#L2-L38","documentation":"An anyhow error-context wrapper produced by extract_disk_access() in turbo-tasks-fs: any std::io error that is NOT NotFound or InvalidFilename (e.g. PermissionDenied, a disk I/O failure) is wrapped with the context 'reading file <path>'. This is a generic filesystem-read failure surfaced by Turbopack's virtual filesystem layer.","triggerScenarios":"Turbopack attempts to read a file that exists but the OS denies access or the read fails — permission denied, file locked, disk error, symlink loop, or path-too-long — during a build/dev compilation.","commonSituations":"File permissions too restrictive for the Next.js process; a file deleted/moved mid-build causing a transient read error; network-mounted filesystem hiccup; running the dev server as a different user than owns the files.","solutions":["Check the underlying io::Error kind in the cause chain (permission denied, etc.) and fix that specific OS-level issue.","Verify the Next.js process has read permissions on the path shown in the message.","Ensure the file/path still exists and isn't a broken symlink during the build.","Re-run the build after resolving the filesystem issue; transient NFS/network FS errors often clear."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the Next.js/Turbopack process has read permissions on all source files.","Avoid editing/deleting files mid-build (use a clean working tree for CI builds).","Use reliable local storage for the project; beware flaky network filesystems.","Run the dev/build server under the same user that owns the files."],"tags":["turbopack","filesystem","io","permissions","turbo-tasks-fs"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}