{"record":{"id":"2cec095e2af12c77","repo":"rust-lang/mdBook","slug":"unable-to-determine-the-current-directory","errorCode":null,"errorMessage":"Unable to determine the current directory","messagePattern":"Unable to determine the current directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":135,"sourceCode":"    tracing_subscriber::fmt()\n        .without_time()\n        .with_ansi(std::io::IsTerminal::is_terminal(&std::io::stderr()))\n        .with_writer(std::io::stderr)\n        .with_env_filter(filter)\n        .with_target(with_target)\n        .init();\n}\n\nfn get_book_dir(args: &ArgMatches) -> PathBuf {\n    if let Some(p) = args.get_one::<PathBuf>(\"dir\") {\n        // Check if path is relative from current dir, or absolute...\n        if p.is_relative() {\n            env::current_dir().unwrap().join(p)\n        } else {\n            p.to_path_buf()\n        }\n    } else {\n        env::current_dir().expect(\"Unable to determine the current directory\")\n    }\n}\n\nfn open<P: AsRef<OsStr>>(path: P) {\n    info!(\"Opening web browser\");\n    if let Err(e) = opener::open(path) {\n        error!(\"Error opening web browser: {}\", e);\n    }\n}\n\n#[test]\nfn verify_app() {\n    create_clap_command().debug_assert();\n}\n","sourceCodeStart":117,"sourceCodeEnd":150,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/src/main.rs#L117-L150","documentation":"mdbook's path-resolution helper resolves the serve/open path against the current working directory using `env::current_dir().expect(\"Unable to determine the current directory\")`. This panics when the OS cannot report the cwd — most commonly because the directory has been deleted or is no longer accessible to the process.","triggerScenarios":"Calling `mdbook serve` (or the path-normalizing helper) with no path argument while the process's current working directory has been removed (e.g. shell in a deleted directory), permission loss, or cwd on an unmounted volume.","commonSituations":"Developer deletes the directory they launched mdbook from; running inside a container where WORKDIR was removed; running mdbook from a temp dir that a script cleaned up.","solutions":["`cd` to an existing directory (e.g. the book root) before running mdbook.","Recreate the deleted directory or restart the shell so it re-resolves the cwd.","Pass an explicit `--dest-dir`/path argument so the helper takes the non-cwd branch.","Check filesystem mount/permissions of the working directory (df, ls) if it appears to exist."],"exampleFix":"# before (shell sitting in a deleted dir)\n$ mdbook serve   # panics: Unable to determine the current directory\n# after\n$ cd /path/to/book && mdbook serve","handlingStrategy":"validation","validationCode":"use std::env;\nmatch env::current_dir() {\n    Ok(cwd) if cwd.exists() => { /* safe to proceed */ }\n    _ => {\n        eprintln!(\"current directory unavailable; cd to a valid directory first\");\n        std::process::exit(1);\n    }\n}","typeGuard":null,"tryCatchPattern":"let cwd = env::current_dir().unwrap_or_else(|e| {\n    eprintln!(\"Unable to determine the current directory: {e}\");\n    std::process::exit(1);\n});","preventionTips":["Don't run mdbook from a directory that scripts may delete.","Re-open your shell if the cwd was removed underneath it.","Pass explicit path arguments to avoid the cwd fallback branch.","In scripts, `cd` to a known-existing book root before invoking mdbook."],"tags":["filesystem","panic","current-directory","environment"],"backgroundTag":"current-directory-unavailable","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}