gitbutlerapp/gitbutler · error · anyhow::Error
Invalid section for global key: {key}
Error message
Invalid section for global key: {key} What it means
git_set_global_config and git_remove_global_config validate their key through validate_gitbutler_global_key (crates/but-api/src/legacy/git.rs:113-118): only keys starting with 'gitbutler.' are accepted, so the app cannot clobber arbitrary global git config. git_get_global_config does not enforce this and reads any key.
Source
Thrown at crates/but-api/src/legacy/git.rs:115
Ok(())
})?;
Ok(())
}
#[but_api]
#[instrument(err(Debug))]
pub fn git_get_global_config(key: String) -> Result<Option<String>> {
let config = open_global_config_for_reading()?;
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 caf1f223d3)
Solutions
- Prefix the key with 'gitbutler.' (e.g. 'gitbutler.aiReview')
- For real git config such as user.name or core.editor, write it with git itself (`git config --global ...`) outside this API
- Reads accept any key: use gitGetGlobalConfig to verify the value after writing
Example fix
// before: non-namespaced key
await client.gitSetGlobalConfig('aiReview', 'true');
// error: Invalid section for global key: aiReview
// after: gitbutler namespace
await client.gitSetGlobalConfig('gitbutler.aiReview', 'true');
await client.gitGetGlobalConfig('gitbutler.aiReview'); // 'true' Defensive patterns
Strategy: type-guard
Type guard
function isGitButlerConfigKey(key: string): boolean {
return key.startsWith('gitbutler.');
}
// usage
if (!isGitButlerConfigKey(key)) {
throw new RangeError(`key must be namespaced under 'gitbutler.': ${key}`);
}
await client.gitSetGlobalConfig(key, value); Try / catch
try {
await client.gitSetGlobalConfig(key, value);
} catch (e) {
if (String(e).startsWith('Invalid section for global key')) {
await client.gitSetGlobalConfig(`gitbutler.${key}`, value); // retry namespaced
} else throw e;
} Prevention
- Namespace all app settings written through this API under 'gitbutler.'
- Use plain `git config --global` for anything outside the app's namespace
- Remember reads (gitGetGlobalConfig) accept any key; only writes/removes validate
When it happens
Trigger: Calling gitSetGlobalConfig('user.name', ...) or gitRemoveGlobalConfig('core.editor') with any non-'gitbutler.' key; passing an unprefixed app setting such as 'aiReview' instead of 'gitbutler.aiReview'.
Common situations: Integrations assuming this wraps `git config --global`; settings code that stores the config key without its namespace prefix; typos like 'gitbutler' (missing dot).
Related errors
- Invalid message format
- HTTP Error ${response.statusText}: ${text}
- Invalid parents to disconnect: SelectorSet::None is not allo
- Invalid parent delimitation: requested parent is not a direc
- Invalid parent delimitation: requested child is not a direct
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/f19cf6638321953e.
Report an issue: GitHub.