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 {
			continue

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass the default param types (from macro/introspection registry, e.g. ast.ParamTypes acquired via macros) to Parse.
  2. If building a custom interpreter, initialize and register your param types before calling Parse.
  3. 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

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


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/d87a640a0ff6fe9c. Report an issue: GitHub.