lima-vm/lima · error
function takes at least one string argument
Error message
function takes at least one string argument
What it means
The "indent" template function requires at least one argument: the text to indent. Called with zero arguments it returns this error, which text/template surfaces as an execution error for the pipeline. It is a simple arity validation error from the function's variadic signature.
Source
Thrown at pkg/textutil/textutil.go:76
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
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) {View on GitHub (pinned to dd909d0973)
Solutions
- Add the required argument: use `{{indent 4 .SomeText}}` (optional size, then the string) or `{{indent .SomeText}}` for the default 2-space indent.
- If the argument came from a data field, verify the value passed to ExecuteTemplate actually contains that field and is a string.
- Check FuncHelp (`indent <size>: add spaces to beginning of each line`) for the expected usage.
Example fix
// before
{{ indent }}
// after
{{ indent 4 .StartupScript }} Defensive patterns
Strategy: validation
Validate before calling
// in the template, guard before use:
// {{ if .Text }}{{ indent 4 .Text }}{{ end }}
// or in Go, ensure the field is a non-empty string before ExecuteTemplate Type guard
func indentArgsValid(args ...any) bool {
if len(args) == 0 || len(args) > 2 { return false }
if len(args) == 2 {
if _, ok := args[0].(int); !ok { return false }
}
_, ok := args[len(args)-1].(string)
return ok
} Try / catch
b, err := textutil.ExecuteTemplate(tmpl, data)
if err != nil {
if strings.Contains(err.Error(), "function takes at least one string argument") {
return fmt.Errorf("indent used with no argument in template: %w", err)
}
return err
} Prevention
- Always pass the text argument: `{{indent .Text}}` or `{{indent 4 .Text}}`.
- Wrap pipelines in {{if}} when the source field may be absent.
- Lint templates for bare `indent` invocations before deployment.
- Consult textutil.FuncHelp for correct usage.
When it happens
Trigger: A template containing `{{indent}}` with no arguments — typically a mis-edit of an Ubuntu/cloud-config style template where the argument expression was deleted or evaluates to nothing because the data field is missing (a missing field in text/template yields no arguments for a variadic call only when written literally as no args; more commonly the author wrote {{indent}} instead of {{indent .Text}} or {{indent 4 .Text}}).
Common situations: Hand-editing Lima template YAML and accidentally deleting the argument; copy-pasting a template snippet that references custom fields the caller's data does not provide; typos like `{{ indent }}` while intending `{{ indent 2 .Value }}`.
Related errors
- function takes at most 2 arguments
- the file argument can be specified only for --check mode
- unexpected arguments %v
- can check only a single sudoers file
- --verbatim cannot be used with any of --embed, --embed-all,
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/9354899d0b4daff2.
Report an issue: GitHub.