facebook/flow · error
failed to get current directory
Error message
failed to get current directory
What it means
For relative-path output, `flow ast` calls std::env::current_dir() and .expect("failed to get current directory") — failure panics the command. On Unix the canonical cause is that the process's working directory was deleted (or its permissions revoked) after the shell/tool started: getcwd() then fails with ENOENT because the path to the cwd no longer resolves.
Source
Thrown at rust_port/crates/flow_cli/src/ast_command.rs:287
None
} else {
Some(&mut token_sink as &mut dyn FnMut(flow_parser::TokenSinkResult))
};
// Make the parser as permissive as possible.
// TODO: make these CLI flags
let parse_options = Some(ParseOptions {
components: !no_component_syntax,
enums: !no_enums,
use_strict,
..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 (ast, errors) = match file_type {
AstFileType::FileJs => {
// flow ast is a standalone parser - use the raw constructor
// so paths are stored as-is without root stripping.
let filekey = filename
.clone()
.map(|filename| FileKey::new(FileKeyInner::SourceFile(filename)));
let (ocaml_ast, errors) = match filekey.clone() {
Some(filekey) => flow_parser::parse_program_file::<()>(
false,
token_sink,View on GitHub (pinned to f88ac94bcf)
Solutions
- cd into an existing directory and rerun the command.
- Recreate the deleted directory, or restart the shell/editor/daemon so it picks up a valid cwd.
- In scripts and long-running tools, avoid anchoring to directories that other jobs delete.
Example fix
# before: shell still sits in a directory that was deleted cd /tmp/gone-build && flow ast --filename x.js # panics: failed to get current directory # after: move to a live directory first cd "$HOME" && flow ast --filename /real/path/x.js
Defensive patterns
Strategy: validation
Validate before calling
# Run before invoking Flow from a possibly-stale shell or daemon. pwd >/dev/null 2>&1 || echo "cwd is gone: cd to an existing directory first"
Prevention
- cd to a stable directory before invoking the CLI in scripts.
- Restart shells/editors/daemons after their working directory is deleted.
- Do not anchor long-running tools to build output dirs that other jobs clean.
When it happens
Trigger: Invoking flow ast with relative-path output from a shell, editor, or daemon whose cwd was deleted after it started — another terminal rm -rf of a build dir, a clean step removing the checkout, container layer removal.
Common situations: A terminal left sitting in a removed build/output directory; scripts that cd into temp dirs later cleaned by another job; CI steps running after the workspace directory was wiped; editors launched from a since-deleted directory.
Related errors
- failed to read stdin
- invalid line
- invalid column
- failed to get current directory
- failed to write json errors
AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20).
Data as JSON: /api/errors/aa25859d237fc4f2.
Report an issue: GitHub.