Hmbown/CodeWhale · error

Failed to parse requirements file

Error message

Failed to parse requirements file {}; file contents were omitted

What it means

Thrown while loading the requirements file: it exists and reads fine, but its contents do not parse as TOML into `RequirementsFile`. As everywhere in this codebase, the parse failure message quotes only the path and omits contents to keep potentially sensitive text out of logs.

Solutions

  1. Fix the TOML syntax in the requirements file at the quoted path (validate with a TOML parser)
  2. Check the `allowed_approval_policies` array entries are valid TOML strings
  3. Restore the file from version control or delete it if you do not need requirements overrides (absence is allowed)

Example fix

// before
allowed_approval_policies = [untrusted, on-request]
// after
allowed_approval_policies = ["untrusted", "on-request"]
Defensive patterns

Strategy: validation

Validate before calling

let contents = std::fs::read_to_string(&requirements_path)?;
contents.parse::<toml::Value>().map_err(|e| anyhow!("requirements TOML invalid: {e}"))?;

Try / catch

match load_requirements(&path) {
    Err(e) if e.to_string().contains("Failed to parse requirements file") => {
        eprintln!("Requirements file invalid at {} — ignoring overrides", path.display());
        Ok(())
    }
    other => other,
}

Prevention

When it happens

Trigger: Loading the requirements file (e.g. `allowed_approval_policies`) via the TOML parse step; a missing file is silently skipped (`return Ok(())`), so this error only fires on present-but-invalid content.

Common situations: Hand-editing the requirements TOML with a syntax slip; a policy tool writing a partially-formatted file; adding an `allowed_approval_policies` entry with unquoted or malformed TOML values.

Understand the failure class

Related errors


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

Appendix: source

Thrown at crates/tui/src/config.rs:11726

    configured.is_some_and(|base| !base.trim().is_empty())
}

fn apply_requirements(config: &mut Config) -> Result<()> {
    let path = config
        .requirements_path
        .as_deref()
        .map(expand_path)
        .or_else(default_requirements_path);
    let Some(path) = path else {
        return Ok(());
    };
    if !path.exists() {
        return Ok(());
    }
    let contents = fs::read_to_string(&path)
        .with_context(|| format!("Failed to read requirements file: {}", path.display()))?;
    let requirements: RequirementsFile = toml::from_str(&contents).map_err(|_| {
        anyhow::anyhow!(
            "Failed to parse requirements file {}; file contents were omitted",
            codewhale_config::quote_os_path(&path)
        )
    })?;

    if !requirements.allowed_approval_policies.is_empty()
        && let Some(policy) = config.approval_policy.as_ref()
    {
        let policy = policy.to_ascii_lowercase();
        if !requirements
            .allowed_approval_policies
            .iter()
            .any(|p| p.eq_ignore_ascii_case(&policy))
        {
            anyhow::bail!(
                "approval_policy '{policy}' is not allowed by requirements ({})",
                requirements.allowed_approval_policies.join(", ")
            );

View on GitHub (pinned to 73e0f67d83)