{"record":{"id":"0fac0f06da77da14","repo":"gofr-dev/gofr","slug":"endpoint-d-invalid-mux-pattern-w","errorCode":null,"errorMessage":"endpoint[%d]: invalid mux pattern: %w","messagePattern":"endpoint\\[(.+?)\\]: invalid mux pattern: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/rbac/config.go","lineNumber":222,"sourceCode":"\t// Reject wildcard patterns\n\tif err := c.checkWildcardPattern(path, index); err != nil {\n\t\treturn err\n\t}\n\n\t// Reject old regex patterns\n\tif err := c.checkRegexPattern(path, index); err != nil {\n\t\treturn err\n\t}\n\n\t// Reject regex indicators outside of variable constraints\n\tif err := c.checkRegexIndicators(path, index); err != nil {\n\t\treturn err\n\t}\n\n\t// Validate mux pattern syntax if it contains variables\n\tif isMuxPattern(path) {\n\t\tif err := validateMuxPattern(path); err != nil {\n\t\t\treturn fmt.Errorf(\"endpoint[%d]: invalid mux pattern: %w\", index, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// checkWildcardPattern checks if path contains wildcard pattern.\nfunc (*Config) checkWildcardPattern(path string, index int) error {\n\tif strings.Contains(path, \"/*\") {\n\t\treturn fmt.Errorf(\"endpoint[%d]: %w: %s. Examples: /api/{resource} for single-level or /api/{path:.*} for multi-level\",\n\t\t\tindex, errWildcardPatternNotSupported, path)\n\t}\n\n\treturn nil\n}\n\n// checkRegexPattern checks if path contains old regex pattern.\nfunc (*Config) checkRegexPattern(path string, index int) error {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/rbac/config.go#L204-L240","documentation":"validateEndpointPath detected the path uses gorilla/mux variable syntax ({var}) and validateMuxPattern found the pattern syntactically invalid. RBAC paths must be valid mux patterns so routing and permission matching agree.","triggerScenarios":"An endpoint path like /api/{id or /api/{id:} or /api/users[0]} — malformed braces, empty variable names, or invalid constraint expressions — passed to EnableRBAC/LoadPermissions.","commonSituations":"Hand-writing mux patterns with unbalanced braces; copying patterns from regex-style routers; typos in variable constraints like {id:[a-z instead of {id:[a-z]+}.","solutions":["Balance all braces and give every variable a name: /api/{id}.","If using a constraint, keep the colon and a valid regex: /api/users/{id:[0-9]+}.","Replace multi-level needs with /api/{path:.*} instead of several broken variables.","Test the pattern against your mux router to confirm it compiles/matches."],"exampleFix":"// before\npath: \"/api/users/{id\"\n// after\npath: \"/api/users/{id:[0-9]+}\"","handlingStrategy":"validation","validationCode":"func validMuxPath(p string) bool {\n    depth := 0\n    for _, r := range p {\n        switch r {\n        case '{':\n            depth++\n        case '}':\n            depth--\n            if depth < 0 { return false }\n        }\n    }\n    if depth != 0 { return false }\n    for _, m := range muxVarRe.FindAllStringSubmatch(p, -1) {\n        if m[1] == \"\" { return false } // empty variable name\n    }\n    return true\n}\nvar muxVarRe = regexp.MustCompile(`\\{([^:}]*)(:[^}]*)?\\}`)","typeGuard":null,"tryCatchPattern":"for i, ep := range endpoints {\n    if !validMuxPath(ep.Path) { return fmt.Errorf(\"endpoint[%d]: bad mux pattern %q\", i, ep.Path) }\n}","preventionTips":["Test each pattern against the real mux router in unit tests.","Keep brace count balanced; never leave an unclosed {var.","Always name variables; provide valid regex constraints after ':'.","Only copy patterns from mux documentation, not regex routers."],"tags":["go","rbac","mux","routing","validation"],"backgroundTag":"invalid-route-pattern","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}