{"record":{"id":"03aff16659b5b52a","repo":"git-ecosystem/git-credential-manager","slug":"must-have-a-specific-configuration-level-filter-to","errorCode":null,"errorMessage":"Must have a specific configuration level filter to modify values.","messagePattern":"Must have a specific configuration level filter to modify values\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Core/GitConfiguration.cs","lineNumber":806,"sourceCode":"\n                switch (git.ExitCode)\n                {\n                    case 0: // OK\n                    case 5: // Trying to unset a value that does not exist\n                        InvalidateCache();\n                        break;\n                    default:\n                        _trace.WriteLine($\"Failed to unset all multivar '{name}' with value regex '{valueRegex}' (exit={git.ExitCode}, level={level})\");\n                        throw GitProcess.CreateGitException(git, $\"Failed to unset all Git configuration multi-valued entries '{name}'\");\n                }\n            }\n        }\n\n        private static void EnsureSpecificLevel(GitConfigurationLevel level)\n        {\n            if (level == GitConfigurationLevel.All)\n            {\n                throw new InvalidOperationException(\"Must have a specific configuration level filter to modify values.\");\n            }\n        }\n\n        private static string GetLevelFilterArg(GitConfigurationLevel level)\n        {\n            switch (level)\n            {\n                case GitConfigurationLevel.System:\n                    return \"--system\";\n                case GitConfigurationLevel.Global:\n                    return \"--global\";\n                case GitConfigurationLevel.Local:\n                    return \"--local\";\n                case GitConfigurationLevel.Unknown:\n                default:\n                    return null;\n            }\n        }","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitConfiguration.cs#L788-L824","documentation":"GitConfiguration modification paths call EnsureSpecificLevel, which rejects GitConfigurationLevel.All: writing or modifying configuration requires a specific level (System, Global, Local, etc.) because git itself needs --system/--global/--local style scoping to know which file to change. Reading may use All, but writes cannot.","triggerScenarios":"Calling a set/unset/modify API on GitProcessConfiguration with level == GitConfigurationLevel.All, e.g. config.SetValue(..., GitConfigurationLevel.All, ...) instead of naming the exact level to persist into.","commonSituations":"Developers reusing a level value read with All and passing it to a write; UI code defaulting to All; helper functions that accept a level parameter receiving All from generic call sites.","solutions":["Pass an explicit level such as GitConfigurationLevel.Global or Local when modifying values.","Map 'Any' semantics to a deliberate default (e.g. Global for user-wide settings) before writing.","Guard call sites with a check that level != GitConfigurationLevel.All before invoking write APIs."],"exampleFix":"// before\nconfig.SetValue(Constants.GitConfiguration.Credential.SectionName, \"helper\", helper, GitConfigurationLevel.All);\n// after\nconfig.SetValue(Constants.GitConfiguration.Credential.SectionName, \"helper\", helper, GitConfigurationLevel.Global);","handlingStrategy":"validation","validationCode":"if (level == GitConfigurationLevel.All)\n    throw new InvalidOperationException(\"Writes require a specific configuration level (e.g. Global).\");","typeGuard":"bool IsWritableLevel(GitConfigurationLevel level) => level != GitConfigurationLevel.All;","tryCatchPattern":"try\n{\n    config.SetValue(section, property, value, level);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"specific configuration level\"))\n{\n    // retry with an explicit level such as GitConfigurationLevel.Global\n}","preventionTips":["Use GitConfigurationLevel.All only for reads.","Default writes to an explicit level (Global for user settings, Local for repo settings).","Validate level parameters in wrapper APIs before invoking writes.","Never pass through a user-supplied 'Any' option into write APIs."],"tags":["git-config","configuration","invalid-state","write-operation"],"backgroundTag":"invalid-config-value","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}