kataras/iris · error

expects one or more input arguments

Error message

 expects one or more input arguments

What it means

When registering a jet global function via AddVar/AddFunc wrapper, the generated jet.Func panics if it is invoked with zero arguments, because the underlying generalFunc needs at least one input string. The panic message names the function that was called without arguments.

Source

Thrown at view/jet.go:144

	return s
}

// JetArguments is a type alias of `jet.Arguments`,
// can be used on `AddFunc$funcBody`.
type JetArguments = jet.Arguments

// AddFunc should adds a global function to the jet template set.
func (s *JetEngine) AddFunc(funcName string, funcBody any) {
	// if something like "urlpath" is registered.
	if generalFunc, ok := funcBody.(func(string, ...any) string); ok {
		// jet, unlike others does not accept a func(string, ...any) string,
		// instead it wants:
		// func(JetArguments) reflect.Value.

		s.AddVar(funcName, jet.Func(func(args JetArguments) reflect.Value {
			n := args.NumOfArguments()
			if n == 0 { // no input, don't execute the function, panic instead.
				panic(funcName + " expects one or more input arguments")
			}

			firstInput := args.Get(0).String()

			if n == 1 { // if only the first argument is given.
				return reflect.ValueOf(generalFunc(firstInput))
			}

			// if has variadic.

			variadicN := n - 1
			variadicInputs := make([]any, variadicN) // except the first one.

			for i := 0; i < variadicN; i++ {
				variadicInputs[i] = args.Get(i + 1).Interface()
			}

			return reflect.ValueOf(generalFunc(firstInput, variadicInputs...))

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass at least one argument in the template: {{ myfunc("x") }}
  2. Check every template using the function after changing its signature
  3. Add a compile-time/template test that executes all templates at startup to catch this early

Example fix

// before (template)
{{ uppercase() }}
// after
{{ uppercase("name") }}
Defensive patterns

Strategy: validation

Validate before calling

// in templates always pass an argument; add a startup template render test
n := len(args)
if n == 0 { return fallbackValue } // wrap your jet.Func defensively

Try / catch

defer func() { if r := recover(); r != nil { log.Printf("jet func panic: %v", r); http.Error(w, "template error", 500) } }()

Prevention

When it happens

Trigger: Calling a template-registered function (from AddFunc/AddVar wrapping a func(string) R) with no arguments inside a jet template, e.g. {{ myfunc() }}.

Common situations: Template typo omitting the argument; refactor changed the function to require a parameter while templates still call it bare.

Related errors


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