Hmbown/CodeWhale · error · anyhow::Error

failed to edit permissions at {}; file contents were omitted

Error message

failed to edit permissions at {}; file contents were omitted

What it means

parse_permissions_document parses the raw permissions file with toml_edit before applying an edit (the edit-path variant of the permissions parse). Empty or whitespace-only files are treated as fresh documents; any other content that fails toml_edit raises this error and aborts the edit before writing.

Source

Thrown at crates/config/src/lib.rs:6058

    let permissions = if raw.trim().is_empty() {
        PermissionsToml::default()
    } else {
        toml::from_str(&raw).map_err(|_| {
            anyhow::anyhow!(
                "failed to parse permissions at {}; file contents were omitted",
                quote_os_path(path)
            )
        })?
    };
    Ok((file_exists, raw, permissions))
}

fn parse_permissions_document(path: &Path, raw: &str) -> Result<toml_edit::DocumentMut> {
    if raw.trim().is_empty() {
        Ok(toml_edit::DocumentMut::new())
    } else {
        raw.parse::<toml_edit::DocumentMut>().map_err(|_| {
            anyhow::anyhow!(
                "failed to edit permissions at {}; file contents were omitted",
                quote_os_path(path)
            )
        })
    }
}

fn parse_generated_permissions(path: &Path, body: &str) -> Result<PermissionsToml> {
    toml::from_str(body).map_err(|_| {
        anyhow::anyhow!(
            "generated invalid permissions document for {}; file contents were omitted",
            quote_os_path(path)
        )
    })
}

fn permission_removal_token(path: &Path, raw: &str, index: usize) -> String {
    let mut hasher = Sha256::new();

View on GitHub (pinned to 8880682c63)

Solutions

  1. Fix the file's TOML syntax; a validator pinpoints the line
  2. Remove duplicate keys
  3. As a reset path, back up and delete the permissions file so it regenerates; existing grants are lost and must be re-allowed
Defensive patterns

Strategy: validation

Validate before calling

// Before a permissions edit, prove the file parses with toml_edit:
fn permissions_document_is_editable(path: &std::path::Path) -> bool {
    std::fs::read_to_string(path)
        .map(|raw| raw.trim().is_empty() || raw.parse::<toml_edit::DocumentMut>().is_ok())
        .unwrap_or(false)
}

Try / catch

On Err, abort the edit (the code writes nothing on failure) and route the user to repair or reset; retrying the edit without fixing the file cannot succeed.

Prevention

When it happens

Trigger: Calling a permissions-mutating API while the on-disk permissions file has invalid TOML (bad syntax or duplicate keys). Note the split: the typed load fails at line 6044; this line fails the toml_edit edit path.

Common situations: Manual edits, truncated files after a crash, or schema drift across versions, same as the typed parse variant.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/00f05aa3294c7329. Report an issue: GitHub.