{"record":{"id":"9354899d0b4daff2","repo":"lima-vm/lima","slug":"function-takes-at-least-one-string-argument","errorCode":null,"errorMessage":"function takes at least one string argument","messagePattern":"function takes at least one string argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/textutil/textutil.go","lineNumber":76,"sourceCode":"\t\tvar b bytes.Buffer\n\t\tenc := json.NewEncoder(&b)\n\t\tenc.SetEscapeHTML(false)\n\t\tif err := enc.Encode(v); err != nil {\n\t\t\tpanic(fmt.Errorf(\"failed to marshal as JSON: %+v: %w\", v, err))\n\t\t}\n\t\treturn strings.TrimSuffix(b.String(), \"\\n\")\n\t},\n\t\"yaml\": func(v any) string {\n\t\tvar b bytes.Buffer\n\t\tenc := yaml.NewEncoder(&b)\n\t\tif err := enc.Encode(v); err != nil {\n\t\t\tpanic(fmt.Errorf(\"failed to marshal as YAML: %+v: %w\", v, err))\n\t\t}\n\t\treturn \"---\\n\" + strings.TrimSuffix(b.String(), \"\\n\")\n\t},\n\t\"indent\": func(a ...any) (string, error) {\n\t\tif len(a) == 0 {\n\t\t\treturn \"\", errors.New(\"function takes at least one string argument\")\n\t\t}\n\t\tif len(a) > 2 {\n\t\t\treturn \"\", errors.New(\"function takes at most 2 arguments\")\n\t\t}\n\t\tvar ok bool\n\t\tsize := 2\n\t\tif len(a) > 1 {\n\t\t\tif size, ok = a[0].(int); !ok {\n\t\t\t\treturn \"\", errors.New(\"optional first argument must be an integer\")\n\t\t\t}\n\t\t}\n\t\ttext := \"\"\n\t\tif text, ok = a[len(a)-1].(string); !ok {\n\t\t\treturn \"\", errors.New(\"last argument must be a string\")\n\t\t}\n\t\treturn IndentString(size, text), nil\n\t},\n\t\"missing\": func(a ...any) (string, error) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/textutil/textutil.go#L58-L94","documentation":"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.","triggerScenarios":"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}}).","commonSituations":"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 }}`.","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."],"exampleFix":"// before\n{{ indent }}\n// after\n{{ indent 4 .StartupScript }}","handlingStrategy":"validation","validationCode":"// in the template, guard before use:\n// {{ if .Text }}{{ indent 4 .Text }}{{ end }}\n// or in Go, ensure the field is a non-empty string before ExecuteTemplate","typeGuard":"func indentArgsValid(args ...any) bool {\n    if len(args) == 0 || len(args) > 2 { return false }\n    if len(args) == 2 {\n        if _, ok := args[0].(int); !ok { return false }\n    }\n    _, ok := args[len(args)-1].(string)\n    return ok\n}","tryCatchPattern":"b, err := textutil.ExecuteTemplate(tmpl, data)\nif err != nil {\n    if strings.Contains(err.Error(), \"function takes at least one string argument\") {\n        return fmt.Errorf(\"indent used with no argument in template: %w\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["templates","argument-validation","lima-yaml"],"backgroundTag":"template-function-arity-error","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}