{"record":{"id":"c846e5fe48c7f7ec","repo":"denoland/deno","slug":"path-has-no-root","errorCode":null,"errorMessage":"Path has no root.","messagePattern":"Path has no root\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ext/fs/std_fs.rs","lineNumber":1074,"sourceCode":"        blocks: result.f_blocks as _,\n        bfree: result.f_bfree as _,\n        bavail: result.f_bavail as _,\n        files: result.f_files as _,\n        ffree: result.f_ffree as _,\n      })\n    }\n  }\n  #[cfg(windows)]\n  {\n    use std::ffi::OsStr;\n    use std::os::windows::ffi::OsStrExt;\n\n    use windows_sys::Win32::Storage::FileSystem::GetDiskFreeSpaceW;\n\n    let _ = bigint;\n    let path = path.canonicalize()?;\n    let root = path.ancestors().last().ok_or_else(|| {\n      std::io::Error::new(ErrorKind::NotFound, \"Path has no root.\")\n    })?;\n    let mut root = OsStr::new(root).encode_wide().collect::<Vec<_>>();\n    root.push(0);\n    let mut sectors_per_cluster = 0;\n    let mut bytes_per_sector = 0;\n    let mut available_clusters = 0;\n    let mut total_clusters = 0;\n    let mut code = 0;\n    let mut retries = 0;\n    // We retry here because libuv does: https://github.com/libuv/libuv/blob/fa6745b4f26470dae5ee4fcbb1ee082f780277e0/src/win/fs.c#L2705\n    while code == 0 && retries < 2 {\n      // SAFETY: Normal GetDiskFreeSpaceW usage.\n      code = unsafe {\n        GetDiskFreeSpaceW(\n          root.as_ptr(),\n          &mut sectors_per_cluster,\n          &mut bytes_per_sector,\n          &mut available_clusters,","sourceCodeStart":1056,"sourceCodeEnd":1092,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fs/std_fs.rs#L1056-L1092","documentation":"On Windows, Deno.statfs() canonicalizes the path, walks ancestors() to the last element (the drive root) and queries GetDiskFreeSpaceW. 'Path has no root.' (io::ErrorKind::NotFound) is the defensive fallback when that last ancestor is absent (ext/fs/std_fs.rs:1074). A canonicalized absolute Windows path always has a root, so this error is effectively unreachable through the public API and indicates an internal invariant break.","triggerScenarios":"Not reproducible from JavaScript in practice; it would require canonicalize() to return a relative path on Windows (e.g. unusual device paths mis-resolving through a subst mapping or VERBATIM prefix).","commonSituations":"Essentially never seen; if it appears, it is a Deno bug tied to exotic path forms — worth reporting with the exact input path.","solutions":["Pass an absolute path of an existing directory to Deno.statfs","Update Deno — device-path handling in canonicalize has changed between versions","If it still reproduces, file a Deno issue including the exact path string"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function statfsSafe(path: string): Deno.StatFs {\n  const real = Deno.realPathSync(path); // absolute, existing path\n  if (!real.startsWith('/') && !/^[A-Za-z]:[\\\\/]/.test(real)) {\n    throw new Error(`Refusing statfs on non-absolute path: ${path}`);\n  }\n  return Deno.statfsSync(real);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const fs = Deno.statfsSync(dir);\n} catch (e) {\n  if (e instanceof Error && /Path has no root/.test(e.message)) {\n    // defensive Deno check misfired — report with the exact path\n    throw new Error(`Deno statfs failed to derive a drive root for: ${dir}`);\n  }\n  throw e;\n}","preventionTips":["Pass absolute paths of existing directories to Deno.statfs","Keep Deno updated — Windows device-path canonicalization has changed between versions","Treat this near-unreachable error as a bug report candidate, not an input problem"],"tags":["windows","statfs","filesystem","defensive-check","deno"],"backgroundTag":"invalid-filesystem-path","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}