Hmbown/CodeWhale · error · anyhow::Error

uses variable expansion; workspace .env values must be…

Error message

{} uses variable expansion; workspace .env values must be literal to prevent ambient-secret substitution

What it means

Workspace .env files are loaded to source provider credentials, but only literal values are accepted. If the file text contains variable-expansion syntax (e.g. ${VAR} or $VAR), load_workspace_dotenv_credentials_from_path rejects the whole file, because expansion could substitute ambient environment values — including unrelated secrets — into what look like literal config values.

Solutions

  1. Replace ${VAR}/$VAR references in the workspace .env with their literal resolved values.
  2. Move expansion-dependent values to your real environment (export in the shell) instead of the .env file.
  3. Keep expansion-using .env files outside the workspace so they are not picked up.
  4. Strip or comment out the offending line dotenv_has_variable_expansion flags.

Example fix

// before (.env)
API_KEY=${OPENAI_API_KEY}
// after (.env)
API_KEY=sk-literal-value-here
Defensive patterns

Strategy: validation

Validate before calling

// shell
grep -nE '\$\{?[A-Za-z_][A-Za-z0-9_]*\}?' .env && echo 'expansion not allowed in workspace .env' && exit 1

Prevention

When it happens

Trigger: Placing a .env at the workspace root whose values contain $VAR or ${VAR} interpolation, then starting Codewhale which attempts to load workspace dotenv credentials.

Common situations: Copying a docker-compose-style .env with ${VAR} syntax into the workspace, inheriting a team .env that uses expansion, or shell-generated .env files that interpolate values.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/3ea05322ae25bb07. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lib.rs:2834

                return Err(anyhow!(
                    "could not inspect {}: {error}",
                    candidate.display()
                ));
            }
        }
        if ancestor == boundary {
            break;
        }
    }
    Ok(None)
}

fn load_workspace_dotenv_credentials_from_path(path: &Path) -> Result<WorkspaceDotenvReport> {
    let contents = read_stable_workspace_dotenv(path)?;
    let text = std::str::from_utf8(&contents)
        .map_err(|_| anyhow!("{} is not valid UTF-8", path.display()))?;
    if dotenv_has_variable_expansion(text) {
        bail!(
            "{} uses variable expansion; workspace .env values must be literal to prevent ambient-secret substitution",
            path.display()
        );
    }

    let mut report = WorkspaceDotenvReport {
        path: path.to_path_buf(),
        ..WorkspaceDotenvReport::default()
    };
    let entries = dotenvy::from_read_iter(std::io::Cursor::new(contents))
        .collect::<std::result::Result<Vec<_>, _>>()
        .map_err(|_| anyhow!("{} could not be parsed safely", path.display()))?;
    for entry in entries {
        let (key, value) = entry;
        if !is_workspace_dotenv_credential_key(&key) {
            report.ignored.insert(key);
            continue;
        }

View on GitHub (pinned to 73e0f67d83)