nikivdev/code · error · anyhow::Error

env file not found: {}

Error message

env file not found: {}

What it means

Raised by `push`, which uploads the local `.env` file to the cloud environment, when the resolved env file path (via `resolve_env_file_path()`) does not exist on disk. The CLI checks `env_path.exists()` before reading and bails with the path included in the message.

Source

Thrown at src/env.rs:2487

        content.push_str(&format!("{}=\"{}\"\n", key, escaped));
    }

    let env_path = resolve_env_file_path()?;
    if let Some(parent) = env_path.parent() {
        fs::create_dir_all(parent)?;
    }
    fs::write(&env_path, &content)?;

    println!("✓ Wrote {} env vars to {}", vars.len(), env_path.display());

    Ok(())
}

/// Push local .env to cloud.
fn push(environment: &str) -> Result<()> {
    let env_path = resolve_env_file_path()?;
    if !env_path.exists() {
        bail!("env file not found: {}", env_path.display());
    }

    let content = fs::read_to_string(&env_path)?;
    let vars = parse_env_file(&content);

    if vars.is_empty() {
        println!("No env vars found in .env");
        return Ok(());
    }

    push_vars(environment, vars)
}

fn push_vars(environment: &str, vars: HashMap<String, String>) -> Result<()> {
    if vars.is_empty() {
        println!("No env vars selected.");
        return Ok(());
    }

View on GitHub (pinned to a747e741ae)

Solutions

  1. Create the `.env` file in the project root (or the configured location) and add the variables to push.
  2. Run the command from the directory that contains the `.env` file.
  3. Check the env-file path configuration that `resolve_env_file_path()` uses and correct it if it points elsewhere.

Example fix

# before
f env push staging   // env file not found: ./.env
# after
printf 'API_KEY=xyz\n' > .env
f env push staging
Defensive patterns

Strategy: validation

Validate before calling

// Check the env file before pushing:
if !Path::new(".env").exists() {
    eprintln!("error: .env missing; create it or cd to the project root");
    std::process::exit(1);
}

Prevention

When it happens

Trigger: Running `f env push <environment>` in a directory without a `.env` file (or wherever `resolve_env_file_path()` points), or with a configured env file path that does not exist.

Common situations: New project before any `.env` is created; running the command from the wrong working directory; renamed or gitignored-and-deleted `.env`; custom env-file path misconfigured in flow.toml.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/9ea07a99022a984c. Report an issue: GitHub.