{"record":{"id":"f7123974a4e56f00","repo":"gitbutlerapp/gitbutler","slug":"cannot-pass-both-local-and-global","errorCode":null,"errorMessage":"Cannot pass both --local and --global","messagePattern":"Cannot pass both --local and --global","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/config.rs","lineNumber":61,"sourceCode":"impl From<AiKeyOption> for String {\n    fn from(value: AiKeyOption) -> Self {\n        match value {\n            AiKeyOption::BringYourOwn => \"Bring your own key\".to_string(),\n            AiKeyOption::ButlerApi => \"Use GitButler API\".to_string(),\n        }\n    }\n}\n\n#[derive(Debug, Clone, Copy)]\nenum AiScope {\n    Global,\n    Local,\n}\n\nimpl AiScope {\n    fn from_flags(local: bool, global: bool) -> Result<Self> {\n        if local && global {\n            anyhow::bail!(\"Cannot pass both --local and --global\")\n        }\n        if local {\n            Ok(AiScope::Local)\n        } else {\n            Ok(AiScope::Global)\n        }\n    }\n\n    fn as_str(self) -> &'static str {\n        match self {\n            AiScope::Global => \"global\",\n            AiScope::Local => \"local\",\n        }\n    }\n}\n\ntype AiConfigInfo = AiConfigurationSnapshot;\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/config.rs#L43-L79","documentation":"AiScope::from_flags validates the --local and --global flags for `but config` AI settings. The two scopes are mutually exclusive: passing both makes the target config file ambiguous, so the command errors.","triggerScenarios":"Running `but config ... --local --global` (any AI config subcommand) with both boolean flags set to true.","commonSituations":"Copy-pasting CLI invocations and combining flag sets; scripts appending --global to an existing command that already had --local; misunderstanding that --global is a default rather than an override.","solutions":["Pass only one of --local or --global.","If neither is passed, the default (Global) scope is used — drop the redundant flag.","Fix any script/alias that appends both flags."],"exampleFix":"// before\nbut config set ai.model gpt-4 --local --global\n// after\nbut config set ai.model gpt-4 --local","handlingStrategy":"validation","validationCode":"const flags = [local, global].filter(Boolean).length;\nif (flags > 1) throw new Error('Pass only one of --local or --global');","typeGuard":null,"tryCatchPattern":"try {\n  execSync(`but config set ai.model ${model} ${scopeFlag}`, { stdio: 'inherit' });\n} catch (err) {\n  if (String(err).includes('both --local and --global')) {\n    execSync(`but config set ai.model ${model} --global`, { stdio: 'inherit' });\n  } else { throw err; }\n}","preventionTips":["Build commands from a single scope variable rather than concatenating flag lists.","Remember omitting both flags defaults to Global scope.","Review scripts for duplicated flag segments after copy-paste edits."],"tags":["cli","flags","mutually-exclusive","config"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}