{"record":{"id":"d87a640a0ff6fe9c","repo":"kataras/iris","slug":"empty-parameter-types","errorCode":null,"errorMessage":"empty parameter types","messagePattern":"empty parameter types","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"macro/interpreter/parser/parser.go","lineNumber":19,"sourceCode":"package parser\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/kataras/iris/v12/macro/interpreter/ast\"\n\t\"github.com/kataras/iris/v12/macro/interpreter/lexer\"\n\t\"github.com/kataras/iris/v12/macro/interpreter/token\"\n)\n\n// Parse takes a route \"fullpath\"\n// and returns its param statements\n// or an error if failed.\nfunc Parse(fullpath string, paramTypes []ast.ParamType) ([]*ast.ParamStatement, error) {\n\tif len(paramTypes) == 0 {\n\t\treturn nil, fmt.Errorf(\"empty parameter types\")\n\t}\n\n\tpathParts := strings.Split(fullpath, \"/\")\n\tp := new(ParamParser)\n\tstatements := make([]*ast.ParamStatement, 0)\n\tfor i, s := range pathParts {\n\t\tif s == \"\" { // if starts with /\n\t\t\tcontinue\n\t\t}\n\n\t\t// if it's not a named path parameter of the new syntax then continue to the next\n\t\t// if s[0] != lexer.Begin || s[len(s)-1] != lexer.End {\n\t\t// \tcontinue\n\t\t// }\n\n\t\t// Modified to show an error on a certain invalid action.\n\t\tif s[0] != lexer.Begin {\n\t\t\tcontinue","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/macro/interpreter/parser/parser.go#L1-L37","documentation":"macro/interpreter/parser.Parse returns 'empty parameter types' when called with an empty paramTypes slice. The parser needs the registered parameter type registry (string, int, alphabetical, etc.) to interpret macro statements like {id:int}; without any types there is nothing to resolve against, so it fails fast.","triggerScenarios":"Calling parser.Parse(fullpath, nil) or Parse(fullpath, []ast.ParamType{}) directly, or via interpreter paths where the macro registry failed to initialize/register any parameter types.","commonSituations":"Custom interpreters or tests invoking Parse directly without passing macro.DefaultMacros/param type registry; clearing or mis-ordering macro registrations before route parsing.","solutions":["Pass the default param types (from macro/introspection registry, e.g. ast.ParamTypes acquired via macros) to Parse.","If building a custom interpreter, initialize and register your param types before calling Parse.","If this appears from stock Iris usage, report/upgrade — stock flows always supply registered types."],"exampleFix":"// before\nstmts, err := parser.Parse(\"/user/{id:int}\", nil)\n// after\nparamTypes := iris.Macro.Introspector().GetParamTypes()\nstmts, err := parser.Parse(\"/user/{id:int}\", paramTypes)","handlingStrategy":"validation","validationCode":"func safeParse(fullpath string, pts []ast.ParamType) ([]*ast.ParamStatement, error) {\n    if len(pts) == 0 {\n        pts = defaultParamTypes()\n    }\n    return parser.Parse(fullpath, pts)\n}","typeGuard":"func hasParamTypes(pts []ast.ParamType) bool { return len(pts) > 0 }","tryCatchPattern":"stmts, err := parser.Parse(fullpath, pts)\nif err != nil {\n    if strings.Contains(err.Error(), \"empty parameter types\") {\n        err = fmt.Errorf(\"param type registry not initialized: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Always initialize the macro registry before parsing routes.","In custom interpreters, assert the param-types slice is non-empty at init.","Cover route parsing with a startup smoke test."],"tags":["go","iris","macro","parser","route-parameters"],"backgroundTag":"missing-parameter-registry","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}