facebook/flow · error

failed to get current directory

Error message

failed to get current directory

What it means

`flow env-builder-debug` resolves a relative positional FILE against the process's working directory using std::env::current_dir, and this expect panics when getcwd fails. On Linux the dominant cause is ENOENT: the shell's (or parent process's) current directory has been deleted while the process still refers to it. The call is only made when a filename was passed and it is relative (use_relative_path).

Source

Thrown at rust_port/crates/flow_cli/src/env_builder_debug_command.rs:131

    AutocompleteHooks {
        id_hook: Box::new(|_, _| false),
        literal_hook: Box::new(|_| false),
        obj_prop_decl_hook: Box::new(|_, _| false),
    }
}

pub fn main(path: Option<String>, filename: Option<String>) {
    let use_relative_path = filename
        .as_ref()
        .is_some_and(|filename| Path::new(filename).is_relative());
    let file = get_file(path, filename);
    let content = file.content_of_file_input_unsafe();
    let parse_options = Some(PERMISSIVE_PARSE_OPTIONS);
    let filename = file.path_of_file_input().map(str::to_owned);
    let filename = if use_relative_path {
        filename.as_ref().map(|filename| {
            flow_common::files::relative_path(
                &std::env::current_dir().expect("failed to get current directory"),
                filename,
            )
        })
    } else {
        filename
    };

    let filekey = filename.map(|filename| FileKey::new(FileKeyInner::SourceFile(filename)));
    let (ast, errors): (flow_parser::ast::Program<Loc, Loc>, Vec<(Loc, ParseError)>) = match filekey
    {
        Some(filekey) => {
            flow_parser::parse_program_file::<()>(false, None, parse_options, filekey, Ok(&content))
        }
        None => flow_parser::parse_program_without_file(false, None, parse_options, Ok(&content)),
    };
    let ast = flow_aloc::loc_to_aloc_ast(&ast);

    if errors.is_empty() {

View on GitHub (pinned to 5c86586199)

Solutions

  1. cd into an existing directory in the same shell and rerun the command.
  2. Pass an absolute FILE path — then use_relative_path is false and current_dir is never called.
  3. Recreate the deleted directory path (`mkdir -p /same/path`) so getcwd succeeds again.
  4. Maintainer fix: match on the Result and skip relativization (or fall back to `.`) instead of panicking.

Example fix

// before
let filename = if use_relative_path {
    filename.as_ref().map(|filename| {
        flow_common::files::relative_path(
            &std::env::current_dir().expect("failed to get current directory"),
            filename,
        )
    })
} else { filename };

// after
let filename = if use_relative_path {
    match std::env::current_dir() {
        Ok(cwd) => filename.as_ref().map(|f| flow_common::files::relative_path(&cwd, f)),
        Err(_) => filename.clone(), // cwd vanished; keep the path as given
    }
} else { filename };
Defensive patterns

Strategy: fallback

Validate before calling

if std::env::current_dir().is_err() {
    eprintln!("current directory no longer exists; use an absolute file path");
}

Try / catch

match std::env::current_dir() {
    Ok(cwd) => flow_common::files::relative_path(&cwd, filename),
    Err(_) => filename.to_string_lossy().into_owned(), // cwd vanished; keep path as given
}

Prevention

When it happens

Trigger: Running `flow env-builder-debug relative/path.js` from a directory that no longer exists on disk — the dir was rm -rf'd, a tempdir was cleaned up, or a container/workspace layer was removed out from under the process.

Common situations: Scripts that cd into a build/temp directory, delete it, and still exec flow; CI cleanup jobs racing test invocation; a terminal session left sitting in a deleted directory (bash shows the classic 'getcwd: cannot access parent directories' symptom).

Related errors


AI-assisted analysis of facebook/flow@5c86586199 (2026-08-20). Data as JSON: /api/errors/32797b3af215c95a. Report an issue: GitHub.