gitbutlerapp/gitbutler · error

Invalid section for global key

Error message

Invalid section for global key: {key}

What it means

When setting or removing global GitButler config entries, the key must live in the 'gitbutler.' config section. validate_gitbutler_global_key rejects any key that does not start with 'gitbutler.', preventing arbitrary global git config from being written through this API.

Solutions

  1. Prefix the key with 'gitbutler.' (e.g. 'gitbutler.myOption')
  2. Use standard git tooling (git config --global) for non-GitButler keys
  3. Check the exact key name for typos

Example fix

// before
await gitSetGlobalConfig("user.name", name);
// after
await gitSetGlobalConfig("gitbutler.userName", name);
Defensive patterns

Strategy: validation

Validate before calling

if (!key.startsWith('gitbutler.')) {
  throw new Error(`Key must be in gitbutler. section: ${key}`);
}
await gitSetGlobalConfig(key, value);

Type guard

function isGitButlerKey(key) { return key.startsWith('gitbutler.'); }

Try / catch

try {
  await gitSetGlobalConfig(key, value);
} catch (e) {
  if (String(e).includes('Invalid section for global key')) {
    await gitSetGlobalConfig(`gitbutler.${key}`, value);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling git_set_global_config or git_remove_global_config with a key like 'user.name' or 'core.editor' (missing the 'gitbutler.' prefix).

Common situations: Frontend passing a plain git config key by mistake; attempting to use the GitButler API to edit general git settings; typos like 'gitbutler.x'.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/f19cf6638321953e. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/legacy/git.rs:113

        Ok(())
    })?;
    Ok(())
}

#[but_api]
#[instrument(err(Debug))]
pub fn git_get_global_config(key: String) -> Result<Option<String>> {
    let config = gix::config(None, &gix::open::Options::default())?;
    Ok(get_config_string(&config, &key))
}

fn get_config_string(config: &gix::config::File, key: &str) -> Option<String> {
    config.string(key).map(|s| s.to_string())
}

fn validate_gitbutler_global_key(key: &str) -> Result<()> {
    if !key.starts_with("gitbutler.") {
        bail!("Invalid section for global key: {key}")
    }
    Ok(())
}

View on GitHub (pinned to 58e5313667)