lima-vm/lima · error

function takes at most 2 arguments

Error message

function takes at most 2 arguments

What it means

The "indent" template function accepts at most two arguments: an optional integer indent size and the string to indent. Supplying three or more arguments returns this error, which text/template reports as a template execution error. It guards the variadic signature against malformed pipelines.

Source

Thrown at pkg/textutil/textutil.go:79

		if err := enc.Encode(v); err != nil {
			panic(fmt.Errorf("failed to marshal as JSON: %+v: %w", v, err))
		}
		return strings.TrimSuffix(b.String(), "\n")
	},
	"yaml": func(v any) string {
		var b bytes.Buffer
		enc := yaml.NewEncoder(&b)
		if err := enc.Encode(v); err != nil {
			panic(fmt.Errorf("failed to marshal as YAML: %+v: %w", v, err))
		}
		return "---\n" + strings.TrimSuffix(b.String(), "\n")
	},
	"indent": func(a ...any) (string, error) {
		if len(a) == 0 {
			return "", errors.New("function takes at least one string argument")
		}
		if len(a) > 2 {
			return "", errors.New("function takes at most 2 arguments")
		}
		var ok bool
		size := 2
		if len(a) > 1 {
			if size, ok = a[0].(int); !ok {
				return "", errors.New("optional first argument must be an integer")
			}
		}
		text := ""
		if text, ok = a[len(a)-1].(string); !ok {
			return "", errors.New("last argument must be a string")
		}
		return IndentString(size, text), nil
	},
	"missing": func(a ...any) (string, error) {
		if len(a) == 0 {
			return "", errors.New("function takes at least one string argument")
		}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Reduce to at most two arguments: `{{indent 4 .Text}}` or `{{indent .Text}}`.
  2. If piping, use `{{.Text | indent 4}}` and do not also pass the text positionally.
  3. Remove duplicate/leftover arguments left from template refactoring; verify against FuncHelp usage.

Example fix

// before
{{ indent 2 4 .ProvisionScript }}
// after
{{ indent 4 .ProvisionScript }}
Defensive patterns

Strategy: validation

Validate before calling

// template-level check: at most size + text
// {{ indent 4 .Text }}  // OK
// Go-side guard for generated pipelines:
if len(args) > 2 { return errors.New("indent: too many arguments") }

Type guard

func indentArityOk(n int) bool { return n >= 1 && n <= 2 }

Try / catch

b, err := textutil.ExecuteTemplate(tmpl, data)
if err != nil {
    if strings.Contains(err.Error(), "function takes at most 2 arguments") {
        return fmt.Errorf("indent called with extra arguments in template: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: A template like `{{indent 2 4 .Text}}` or `{{indent .A .B .C}}` — passing extra positional arguments, accidentally splitting the size and text across multiple pipeline args, or piping a value in and also passing it as an argument (e.g. `{{.Text | indent 2 .Other}}`).

Common situations: Misreading the documented signature `indent <size>` and adding the text twice; refactoring a template to add context and forgetting to remove an old argument; mixing pipe syntax with explicit arguments so the pipeline contributes an extra value.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/3ef7262e656b6831. Report an issue: GitHub.