{"record":{"id":"678060a70f8f5828","repo":"git-ecosystem/git-credential-manager","slug":"no-protocol-name-mapping-is-defined-for-the-given","errorCode":null,"errorMessage":"No protocol name mapping is defined for the given capability.","messagePattern":"No protocol name mapping is defined for the given capability\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/GitCapabilities.cs","lineNumber":96,"sourceCode":"    /// <remarks>\n    /// The protocol name is always lowercase. New entries must be added here\n    /// in lockstep with new <see cref=\"GitCapabilities\"/> flag values to avoid\n    /// emitting an incorrect name to Git.\n    /// </remarks>\n    public static string ToProtocolName(GitCapabilities capability)\n    {\n        // Add each flag's protocol name here as the capability is wired up.\n        // The default lowercase enum name is intentionally NOT used because\n        // some protocol names will not be a single token (e.g. authtype is fine\n        // but a hypothetical \"PasswordExpiryUtc\" would have to map to a\n        // protocol name distinct from its .NET enum name).\n        return capability switch\n        {\n            GitCapabilities.State => \"state\",\n            GitCapabilities.None => throw new ArgumentException(\n                \"Cannot render the None capability to a protocol name.\",\n                nameof(capability)),\n            _ => throw new ArgumentOutOfRangeException(\n                nameof(capability),\n                capability,\n                \"No protocol name mapping is defined for the given capability.\"),\n        };\n    }\n\n    /// <summary>\n    /// Enumerate each individual <see cref=\"GitCapabilities\"/> flag set in\n    /// <paramref name=\"capabilities\"/>, rendered to its on-the-wire protocol name.\n    /// </summary>\n    /// <remarks>\n    /// Returns an empty sequence for <see cref=\"GitCapabilities.None\"/>. Each\n    /// emitted name comes from <see cref=\"ToProtocolName\"/>.\n    /// </remarks>\n    public static IEnumerable<string> ToProtocolNames(GitCapabilities capabilities)\n    {\n        if (capabilities == GitCapabilities.None)\n        {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitCapabilities.cs#L78-L114","documentation":"The default arm of GitCapabilities.ToProtocolName's switch throws ArgumentOutOfRangeException when given a capability value that has no defined protocol name mapping. Unlike None (a deliberate ArgumentException), this fires for any unrecognized or unimplemented enum value — typically a newly added GitCapabilities member that lacks a mapping entry.","triggerScenarios":"Calling ToProtocolName (directly or via ToProtocolNames) with an enum value not covered by the switch — e.g. a capability added in a newer version of the library while the mapping table was not updated, or a cast of an arbitrary integer to GitCapabilities.State.","commonSituations":"Version mismatch between components sharing the GitCapabilities enum; custom code casting raw protocol strings/ints into the enum; library upgrade where new capabilities were introduced.","solutions":["Update to matching library versions on all sides so both the enum and the mapping table agree.","Add a mapping case for the new capability in ToProtocolName if you own the code.","Validate capability values before casting; never cast untrusted integers to the enum without Enum.IsDefined."],"exampleFix":"// before\nvar cap = (GitCapabilities.State)rawValue; // unmapped value\nvar name = cap.ToProtocolName(); // ArgumentOutOfRangeException\n// after\nif (Enum.IsDefined(typeof(GitCapabilities.State), rawValue))\n    var name = ((GitCapabilities.State)rawValue).ToProtocolName();","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(GitCapabilities.State), rawValue))\n    throw new InvalidOperationException($\"Unknown capability value {rawValue}\");","typeGuard":"bool IsKnownCapability(GitCapabilities.State c) =>\n    c == GitCapabilities.None || c == GitCapabilities.State; // extend as mappings are added","tryCatchPattern":"try\n{\n    var name = capability.ToProtocolName();\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogWarning(ex, $\"Capability {capability} has no protocol mapping; check library version alignment.\");\n}","preventionTips":["Keep the GitCapabilities enum and its mapping table updated together when adding capabilities.","Avoid casting raw ints/strings to the enum without Enum.IsDefined.","Synchronize library versions across components that exchange capability values."],"tags":["git-protocol","capabilities","enum","argument-out-of-range"],"backgroundTag":"argument-out-of-range","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"}