facebook/flow · error

failed to get current directory

Error message

failed to get current directory

What it means

get_filenames_from_input builds the list of files to check (from --input-file/-, CLI filename args, or the find-based walker) and resolves every relative name against std::env::current_dir(). That syscall fails with ENOENT when the directory the process was started in has been unlinked, or EACCES when execute permission on it was stripped; the .expect() then panics before any file is processed.

Source

Thrown at rust_port/crates/flow_cli/src/command_utils.rs:120

                    Box::new(move |path: &str| flow_common::files::is_valid_path(&opts, path))
                }
                None => Box::new(|path: &str| path.ends_with(".js")),
            };
            let root = paths[0].clone();
            let others = paths[1..].to_vec();
            Box::new(flow_utils_find::make_next_files(filter, others, root))
        }
    };
    flow_common::files::get_all(&mut *next_files)
}

pub(super) fn get_filenames_from_input(
    allow_imaginary: bool,
    input_file: Option<&str>,
    filenames: Option<&[String]>,
) -> Vec<String> {
    let cwd = std::env::current_dir()
        .expect("failed to get current directory")
        .to_string_lossy()
        .to_string();
    let handle_imaginary = |filename: &str| -> String {
        if allow_imaginary {
            flow_common::files::imaginary_realpath(filename)
        } else {
            let msg = format!("File not found: {:?}", filename);
            flow_common_exit::exit(FlowExitStatus::NoInput, Some(&msg));
        }
    };
    let input_file_filenames = match input_file {
        Some("-") => {
            let stdin = std::io::stdin();
            let lines: Vec<String> = stdin
                .lock()
                .lines()
                .map(|l| l.expect("failed to read stdin"))
                .collect();

View on GitHub (pinned to f88ac94bcf)

Solutions

  1. Run the command again from a directory that exists (`cd /` or re-enter the repo), or recreate the deleted workspace
  2. Fix script ordering so cleanup (rm -rf of temp/workspace dirs) runs strictly after the flow command exits (use trap/finally)
  3. Pass absolute file paths and an explicit --root so resolution never depends on a live cwd
  4. Maintainer: replace the expect with a graceful exit (FlowExitStatus::InputError plus a message) when current_dir errs

Example fix

// before
let cwd = std::env::current_dir()
    .expect("failed to get current directory")
    .to_string_lossy()
    .to_string();

// after
let cwd = match std::env::current_dir() {
    Ok(dir) => dir.to_string_lossy().to_string(),
    Err(e) => flow_common_exit::exit(
        FlowExitStatus::InputError,
        Some(&format!("cannot resolve current directory: {e}")),
    ),
};
Defensive patterns

Strategy: validation

Validate before calling

// Rust: verify cwd is resolvable before invoking the CLI
if std::env::current_dir().is_err() {
    eprintln!("cwd is gone; cd to an existing directory first");
    std::process::exit(1);
}

# Shell wrapper: a deleted cwd makes `cd .` fail
bash -c 'cd . 2>/dev/null || { echo "cwd deleted"; exit 1; }; exec flow "$@"' _ check-contents file.js

Try / catch

let cwd = match std::env::current_dir() {
    Ok(dir) => dir.to_string_lossy().to_string(),
    Err(e) => flow_common_exit::exit(
        FlowExitStatus::InputError,
        Some(&format!("cannot resolve current directory: {e}")),
    ),
};

Prevention

When it happens

Trigger: The shell's cwd (a temp dir, deleted checkout, or removed build dir) is rm -rf'd while a flow invocation is running or about to resolve paths; permissions on the cwd are revoked mid-run; container/sandbox unmounts the cwd.

Common situations: CI ephemeral workspaces cleaned by a concurrent step; scripts that `cd "$(mktemp -d)"` and clean up too early; long-running editors/tasks started from a directory later deleted; Docker volume unmounted underneath the process.

Related errors


AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20). Data as JSON: /api/errors/5871aa7b93f2b50c. Report an issue: GitHub.