{"record":{"id":"f7781ab5fbcfa814","repo":"jdx/mise","slug":"directory-specified-with-cd-does-not-exist-p","errorCode":null,"errorMessage":"Directory specified with --cd does not exist: {}\nPlease check the path and try again.","messagePattern":"Directory specified with --cd does not exist: (.+?)\nPlease check the path and try again\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/mod.rs","lineNumber":1243,"sourceCode":"/// Check if the current working directory exists and warn if not\nfn check_working_directory() {\n    if std::env::current_dir().is_err() {\n        // Try to get the directory path from PWD env var, which might still contain the old path\n        let dir_path = std::env::var(\"PWD\")\n            .or_else(|_| std::env::var(\"OLDPWD\"))\n            .unwrap_or_else(|_| \"(unknown)\".to_string());\n        warn!(\n            \"Current directory does not exist or is not accessible: {}\",\n            dir_path\n        );\n    }\n}\n\n/// Validate the --cd path if provided and return an error if it doesn't exist\nfn validate_cd_path(cd: &Option<PathBuf>) -> Result<()> {\n    if let Some(path) = cd {\n        if !path.exists() {\n            bail!(\n                \"Directory specified with --cd does not exist: {}\\n\\\n                 Please check the path and try again.\",\n                ui::style::epath(path)\n            );\n        }\n        if !path.is_dir() {\n            bail!(\n                \"Path specified with --cd is not a directory: {}\\n\\\n                 Please provide a valid directory path.\",\n                ui::style::epath(path)\n            );\n        }\n    }\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {","sourceCodeStart":1225,"sourceCodeEnd":1261,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/cli/mod.rs#L1225-L1261","documentation":"mise validates the `--cd` global flag before executing any command. If the supplied path does not exist, it cannot change the working directory for config discovery, so it fails fast with this message.","triggerScenarios":"Running any mise command with `mise --cd <path> <cmd>` where `<path>` does not exist on disk (typo, deleted directory, not-yet-created build dir).","commonSituations":"CI scripts computing the path dynamically with a typo; referencing a directory created later in the script; shell variable expansion producing an empty or wrong path.","solutions":["Check the path spelling and existence: `ls <path>` before running mise","Create the directory first if it is generated (`mkdir -p \"$DIR\"`), then run mise","Verify shell variables used in the path expand correctly (echo them before the mise call)"],"exampleFix":"// before\nmise --cd \"$BUILD_DIR\" install\n// after\nmkdir -p \"$BUILD_DIR\"\nmise --cd \"$BUILD_DIR\" install","handlingStrategy":"validation","validationCode":"// bash: verify the directory before passing --cd\n[[ -d \"$DIR\" ]] || { echo \"$DIR missing\"; exit 1; }\nmise --cd \"$DIR\" install","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always `mkdir -p`/verify directories referenced by --cd","Quote and echo path variables in scripts to catch empty expansions","Run mise commands from existing directories when possible"],"tags":["cli","path","directory","argument-validation"],"backgroundTag":"directory-not-found","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}