kataras/iris · error
empty parameter types
Error message
empty parameter types
What it means
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.
Source
Thrown at macro/interpreter/parser/parser.go:19
package parser
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/kataras/iris/v12/macro/interpreter/ast"
"github.com/kataras/iris/v12/macro/interpreter/lexer"
"github.com/kataras/iris/v12/macro/interpreter/token"
)
// Parse takes a route "fullpath"
// and returns its param statements
// or an error if failed.
func Parse(fullpath string, paramTypes []ast.ParamType) ([]*ast.ParamStatement, error) {
if len(paramTypes) == 0 {
return nil, fmt.Errorf("empty parameter types")
}
pathParts := strings.Split(fullpath, "/")
p := new(ParamParser)
statements := make([]*ast.ParamStatement, 0)
for i, s := range pathParts {
if s == "" { // if starts with /
continue
}
// if it's not a named path parameter of the new syntax then continue to the next
// if s[0] != lexer.Begin || s[len(s)-1] != lexer.End {
// continue
// }
// Modified to show an error on a certain invalid action.
if s[0] != lexer.Begin {
continueView on GitHub (pinned to 7bedaf55a0)
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.
Example fix
// before
stmts, err := parser.Parse("/user/{id:int}", nil)
// after
paramTypes := iris.Macro.Introspector().GetParamTypes()
stmts, err := parser.Parse("/user/{id:int}", paramTypes) Defensive patterns
Strategy: validation
Validate before calling
func safeParse(fullpath string, pts []ast.ParamType) ([]*ast.ParamStatement, error) {
if len(pts) == 0 {
pts = defaultParamTypes()
}
return parser.Parse(fullpath, pts)
} Type guard
func hasParamTypes(pts []ast.ParamType) bool { return len(pts) > 0 } Try / catch
stmts, err := parser.Parse(fullpath, pts)
if err != nil {
if strings.Contains(err.Error(), "empty parameter types") {
err = fmt.Errorf("param type registry not initialized: %w", err)
}
return nil, err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Custom interpreters or tests invoking Parse directly without passing macro.DefaultMacros/param type registry; clearing or mis-ordering macro registrations before route parsing.
Related errors
- %s: %w
- %s: invalid path part: dynamic path parameter and other para
- empty regex expression
- ErrEmptyFormField
- dest directory: %s: eval symlinks: %w
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/d87a640a0ff6fe9c.
Report an issue: GitHub.