{"record":{"id":"32797b3af215c95a","repo":"facebook/flow","slug":"failed-to-get-current-directory-32797b","errorCode":null,"errorMessage":"failed to get current directory","messagePattern":"failed to get current directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_cli/src/env_builder_debug_command.rs","lineNumber":131,"sourceCode":"    AutocompleteHooks {\n        id_hook: Box::new(|_, _| false),\n        literal_hook: Box::new(|_| false),\n        obj_prop_decl_hook: Box::new(|_, _| false),\n    }\n}\n\npub fn main(path: Option<String>, filename: Option<String>) {\n    let use_relative_path = filename\n        .as_ref()\n        .is_some_and(|filename| Path::new(filename).is_relative());\n    let file = get_file(path, filename);\n    let content = file.content_of_file_input_unsafe();\n    let parse_options = Some(PERMISSIVE_PARSE_OPTIONS);\n    let filename = file.path_of_file_input().map(str::to_owned);\n    let filename = if use_relative_path {\n        filename.as_ref().map(|filename| {\n            flow_common::files::relative_path(\n                &std::env::current_dir().expect(\"failed to get current directory\"),\n                filename,\n            )\n        })\n    } else {\n        filename\n    };\n\n    let filekey = filename.map(|filename| FileKey::new(FileKeyInner::SourceFile(filename)));\n    let (ast, errors): (flow_parser::ast::Program<Loc, Loc>, Vec<(Loc, ParseError)>) = match filekey\n    {\n        Some(filekey) => {\n            flow_parser::parse_program_file::<()>(false, None, parse_options, filekey, Ok(&content))\n        }\n        None => flow_parser::parse_program_without_file(false, None, parse_options, Ok(&content)),\n    };\n    let ast = flow_aloc::loc_to_aloc_ast(&ast);\n\n    if errors.is_empty() {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/rust_port/crates/flow_cli/src/env_builder_debug_command.rs#L113-L149","documentation":"`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).","triggerScenarios":"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.","commonSituations":"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).","solutions":["cd into an existing directory in the same shell and rerun the command.","Pass an absolute FILE path — then use_relative_path is false and current_dir is never called.","Recreate the deleted directory path (`mkdir -p /same/path`) so getcwd succeeds again.","Maintainer fix: match on the Result and skip relativization (or fall back to `.`) instead of panicking."],"exampleFix":"// before\nlet filename = if use_relative_path {\n    filename.as_ref().map(|filename| {\n        flow_common::files::relative_path(\n            &std::env::current_dir().expect(\"failed to get current directory\"),\n            filename,\n        )\n    })\n} else { filename };\n\n// after\nlet filename = if use_relative_path {\n    match std::env::current_dir() {\n        Ok(cwd) => filename.as_ref().map(|f| flow_common::files::relative_path(&cwd, f)),\n        Err(_) => filename.clone(), // cwd vanished; keep the path as given\n    }\n} else { filename };","handlingStrategy":"fallback","validationCode":"if std::env::current_dir().is_err() {\n    eprintln!(\"current directory no longer exists; use an absolute file path\");\n}","typeGuard":null,"tryCatchPattern":"match std::env::current_dir() {\n    Ok(cwd) => flow_common::files::relative_path(&cwd, filename),\n    Err(_) => filename.to_string_lossy().into_owned(), // cwd vanished; keep path as given\n}","preventionTips":["Pass absolute file paths to flow CLI commands.","Scripts should cd to a stable directory before exec'ing tools.","Recreate (mkdir -p) or leave build/temp workspaces intact while processes use them."],"tags":["cwd","filesystem","getcwd","paths","panic"],"backgroundTag":"deleted-working-directory","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}