Skip to content

Recipe saving fails with 'No such file or directory' error for first-time users #5339

@blackgirlbytes

Description

@blackgirlbytes

Bug Description

When users attempt to save a recipe for the first time, they encounter the error:

Can't save recipes "No such file or directory (os error 2)"

Root Cause

The save_recipe_to_file function in crates/goose/src/recipe/local_recipes.rs does not create the necessary directory structure before attempting to write the recipe file.

The function tries to save recipes to {config_dir}/recipes/ (e.g., ~/Library/Application Support/Block/goose/recipes/ on macOS), but if this directory doesn't exist, fs::write() fails with "No such file or directory".

When This Happens

  • First-time users: The global recipe directory doesn't exist yet
  • Fresh installations: The config directory structure hasn't been created
  • Users who haven't used CLI features: Other goose features create config directories, but recipe saving doesn't

Affected Code

pub fn save_recipe_to_file(recipe: Recipe, file_path: Option<PathBuf>) -> anyhow::Result<PathBuf> {
    let recipe_library_dir = get_recipe_library_dir(true);
    
    let file_path_value = match file_path {
        Some(path) => path,
        None => generate_recipe_filename(&recipe.title, &recipe_library_dir),
    };

    let yaml_content = serde_yaml::to_string(&recipe)?;
    fs::write(&file_path_value, yaml_content)?;  // ← Fails if directory doesn't exist
    Ok(file_path_value)
}

Proposed Solution

Add directory creation before writing the file:

pub fn save_recipe_to_file(recipe: Recipe, file_path: Option<PathBuf>) -> anyhow::Result<PathBuf> {
    let recipe_library_dir = get_recipe_library_dir(true);
    
    let file_path_value = match file_path {
        Some(path) => path,
        None => generate_recipe_filename(&recipe.title, &recipe_library_dir),
    };

    // Create parent directory if it doesn't exist
    if let Some(parent) = file_path_value.parent() {
        fs::create_dir_all(parent)?;
    }

    let yaml_content = serde_yaml::to_string(&recipe)?;
    fs::write(&file_path_value, yaml_content)?;
    Ok(file_path_value)
}

Evidence

Other parts of the codebase already handle this correctly:

  • crates/goose/src/config/base.rs:119: std::fs::create_dir_all(&config_dir)
  • crates/goose/src/session/session_manager.rs:252: fs::create_dir_all(&session_dir)?

Steps to Reproduce

  1. Fresh goose installation
  2. Open goose desktop app
  3. Create a conversation
  4. Try to save it as a recipe
  5. Error occurs: "Can't save recipes 'No such file or directory (os error 2)'"

Environment

  • Affects all platforms (macOS, Linux, Windows)
  • Occurs in both desktop app and potentially CLI usage
  • First-time users are most affected

Metadata

Metadata

Assignees

Labels

hacktoberfestIssues awarding points for Hacktoberfest 2025!mediumWeight label for Hacktoberfest 2025 issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions