{"record":{"id":"bba317c924927a21","repo":"facebook/relay","slug":"unable-to-get-current-working-directory","errorCode":null,"errorMessage":"Unable to get current working directory.","messagePattern":"Unable to get current working directory\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/relay-bin/src/main.rs","lineNumber":399,"sourceCode":"            handle_regenerate_subschema_command(command).await\n        }\n        Commands::ExperimentalCompareDocumentIR(command) => {\n            handle_compare_document_ir_command(command)\n        }\n        #[cfg(unix)]\n        Commands::Server(opt) => handle_server_command(opt).await,\n    };\n\n    if let Err(err) = result {\n        error!(\"{}\", err);\n        std::process::exit(1);\n    }\n}\n\nfn get_config(config_path: Option<PathBuf>) -> Result<Config, Error> {\n    match config_path {\n        Some(config_path) => Config::load(config_path).map_err(Error::ConfigError),\n        None => Config::search(&current_dir().expect(\"Unable to get current working directory.\"))\n            .map_err(Error::ConfigError),\n    }\n}\n\n/// Wire up the OSS CLI's default config extensions: the standard operation\n/// persister (Remote/Local from `project_config.persist`) and the default\n/// extra-artifacts generator. Used by every entry point that drives a real\n/// build.\nfn apply_default_cli_extensions(config: &mut Config) {\n    config.create_operation_persister = Some(Box::new(|project_config| {\n        project_config.persist.as_ref().map(\n            |persist_config| -> Box<dyn OperationPersister + Send + Sync> {\n                match persist_config {\n                    PersistConfig::Remote(remote_config) => {\n                        Box::new(RemotePersister::new(remote_config.clone()))\n                    }\n                    PersistConfig::Local(local_config) => {\n                        Box::new(LocalPersister::new(local_config.clone()))","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/relay-bin/src/main.rs#L381-L417","documentation":"get_config resolves the relay config either from an explicit path or by searching from the current working directory. When no config path is given, current_dir() is unwrapped with .expect(); if the process's working directory cannot be determined (typically because the directory was deleted or is unreadable), it panics with 'Unable to get current working directory.'","triggerScenarios":"Calling any command path that calls get_config (codemod, regenerate-subschema, compiler/LSP commands, foreground server) without --config while current_dir() returns Err.","commonSituations":"Running relay from a directory that was deleted (common in CI workspaces cleaned mid-run); running with cwd pointing at a removed mount; scripts cd-ing into temp dirs that are subsequently wiped.","solutions":["Run relay from an existing directory, or pass --config so current_dir() is never consulted","Recreate/re-enter the directory: `cd /valid/path && relay build`","In scripts, verify the working directory exists before invoking relay","Pass an explicit config path in CI: `relay build --config \"$PWD/relay.config.js\"`"],"exampleFix":"// before\nrm -rf build && cd build && relay build   // cwd deleted -> panic\n// after\nrelay build --config ./relay.config.js    // from a live directory","handlingStrategy":"validation","validationCode":"const cwd = process.cwd();\nconst fs = require('fs');\nif (!fs.existsSync(cwd)) throw new Error('Working directory no longer exists; re-enter it or pass --config.');","typeGuard":null,"tryCatchPattern":"try {\n  await relay(['build']);\n} catch (e) {\n  if (/Unable to get current working directory/.test(e.message)) {\n    console.error('Your cwd was deleted; cd into a valid dir or pass --config.');\n  } else throw e;\n}","preventionTips":["Never cd into directories a script may delete mid-run","Pass --config explicitly so cwd lookup is skipped","Re-enter workspace directories after CI cleanups","Guard scripts against removing their own cwd"],"tags":["filesystem","cwd","config","panic"],"backgroundTag":"cwd-missing","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}