{"record":{"id":"9f287d4e0be523d8","repo":"microsoft/aspire","slug":"unknown-gateway-path-match-type-route-pathtype","errorCode":null,"errorMessage":"Unknown gateway path match type '{route.PathType}'.","messagePattern":"Unknown gateway path match type '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs","lineNumber":1212,"sourceCode":"            else\n            {\n                httpRoute.Spec.Hostnames.AddRange(resolvedHostnames);\n            }\n\n            foreach (var route in hostGroup)\n            {\n                var backendRef = ResolveGatewayBackendRef(route.Endpoint, deploymentTargets, gatewayResource.Name, logger);\n                if (backendRef is null)\n                {\n                    continue;\n                }\n\n                var pathType = route.PathType switch\n                {\n                    GatewayPathMatchType.Exact => \"Exact\",\n                    GatewayPathMatchType.PathPrefix => \"PathPrefix\",\n                    GatewayPathMatchType.RegularExpression => \"RegularExpression\",\n                    _ => throw new InvalidOperationException($\"Unknown gateway path match type '{route.PathType}'.\")\n                };\n\n                var rule = new HttpRouteRuleV1();\n                rule.Matches.Add(new HttpRouteMatchV1\n                {\n                    Path = new HttpRoutePathMatchV1\n                    {\n                        Type = pathType,\n                        Value = route.Path\n                    }\n                });\n                rule.BackendRefs.Add(backendRef);\n                httpRoute.Spec.Rules.Add(rule);\n            }\n\n            if (httpRoute.Spec.Rules.Count > 0)\n            {\n                gatewayResource.GeneratedHttpRoutes.Add(httpRoute);","sourceCodeStart":1194,"sourceCodeEnd":1230,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs#L1194-L1230","documentation":"When emitting HTTPRoute matches, the route's PathType is mapped to a Gateway API path match type string. If route.PathType holds a value outside the GatewayPathMatchType enum (Exact, PathPrefix, RegularExpression), the switch falls through and throws. This is an internal invariant guard against an unmappable path match type.","triggerScenarios":"A GatewayRouteConfig whose PathType is not one of the defined GatewayPathMatchType values, typically from a cast of an invalid int or a default struct value when the enum member was not set.","commonSituations":"Deserializing route configuration from JSON/config where an unknown or numeric enum value was used; a library version mismatch where a new enum member is not handled by the emitting code.","solutions":["Use only GatewayPathMatchType.Exact, GatewayPathMatchType.PathPrefix, or GatewayPathMatchType.RegularExpression when calling WithRoute","Fix any deserialized configuration so it contains a valid enum value","Upgrade the library if a newly added enum member should be supported"],"exampleFix":"// before\nroute.WithRoute(path: \"/x\", endpoint: ep, pathType: (GatewayPathMatchType)99);\n// after\nroute.WithRoute(path: \"/x\", endpoint: ep, pathType: GatewayPathMatchType.PathPrefix);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(GatewayPathMatchType), pathType))\n    throw new ArgumentOutOfRangeException(nameof(pathType), pathType, \"Unknown path match type.\");","typeGuard":"bool IsValidPathType(GatewayPathMatchType t) => t is GatewayPathMatchType.Exact or GatewayPathMatchType.PathPrefix or GatewayPathMatchType.RegularExpression;","tryCatchPattern":"try { route.WithRoute(\"/api\", ep, pathType); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unknown gateway path match type\"))\n{ logger.LogError(ex, \"Invalid GatewayPathMatchType value.\"); }","preventionTips":["Always pass GatewayPathMatchType members, never raw casts or unvalidated config values","When deserializing config, validate enum values with Enum.IsDefined","Re-check enum handling after library upgrades that may add members"],"tags":["kubernetes","gateway-api","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}