{"record":{"id":"d4d5f531b5eb5728","repo":"aaif-goose/goose","slug":"directory-does-not-exist","errorCode":null,"errorMessage":"Directory '{}' does not exist","messagePattern":"Directory '(.+?)' does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/goose-cli/src/session/mod.rs","lineNumber":2081,"sourceCode":"    fn save_recipe(\n        &self,\n        recipe: &goose::recipe::Recipe,\n        filepath_str: &str,\n    ) -> anyhow::Result<PathBuf> {\n        let path_buf = PathBuf::from(filepath_str);\n        let mut path = path_buf.clone();\n\n        // Update the final path if it's relative\n        if path_buf.is_relative() {\n            // If the path is relative, resolve it relative to the current working directory\n            let cwd = std::env::current_dir().context(\"Failed to get current directory\")?;\n            path = cwd.join(&path_buf);\n        }\n\n        // Check if parent directory exists\n        if let Some(parent) = path.parent() {\n            if !parent.exists() {\n                return Err(anyhow::anyhow!(\n                    \"Directory '{}' does not exist\",\n                    parent.display()\n                ));\n            }\n        }\n\n        // Try creating the file\n        let file = std::fs::File::create(path.as_path())\n            .context(format!(\"Failed to create file '{}'\", path.display()))?;\n\n        // Write YAML\n        serde_yaml::to_writer(file, recipe).context(\"Failed to save recipe\")?;\n\n        Ok(path)\n    }\n\n    fn push_message(&mut self, message: Message) {\n        self.messages.push(message);","sourceCodeStart":2063,"sourceCodeEnd":2099,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose-cli/src/session/mod.rs#L2063-L2099","documentation":"When saving a recipe to a user-supplied path, goose resolves relative paths against the current working directory and requires the parent directory to exist before creating the file. A missing parent yields \"Directory '{path}' does not exist\"; goose does not create intermediate directories itself.","triggerScenarios":"goose recipe save new/nested/dir/recipe.yaml (or any save-to-file path) where any intermediate directory does not exist, including relative paths resolved against an unexpected CWD.","commonSituations":"Saving into a not-yet-created folder; path typos; running from a different directory than assumed so the relative parent resolves elsewhere.","solutions":["Create the directory first: mkdir -p recipes/new","Save into an existing directory","Use an absolute path to make resolution independent of CWD"],"exampleFix":"# before\ngoose recipe save recipes/new/foo.yaml   # recipes/new missing\n# after\nmkdir -p recipes/new && goose recipe save recipes/new/foo.yaml","handlingStrategy":"validation","validationCode":"let parent = path.parent().filter(|p| !p.as_os_str().is_empty());\nif let Some(p) = parent {\n    std::fs::create_dir_all(p)?; // goose only checks existence; it does not mkdir\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the target directory (mkdir -p) before saving","Use absolute paths when the CWD is uncertain","Check for typos in nested relative paths"],"tags":["filesystem","recipe","cli","validation"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}