{"record":{"id":"3ef7262e656b6831","repo":"lima-vm/lima","slug":"function-takes-at-most-2-arguments","errorCode":null,"errorMessage":"function takes at most 2 arguments","messagePattern":"function takes at most 2 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/textutil/textutil.go","lineNumber":79,"sourceCode":"\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) {\n\t\tif len(a) == 0 {\n\t\t\treturn \"\", errors.New(\"function takes at least one string argument\")\n\t\t}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/textutil/textutil.go#L61-L97","documentation":"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.","triggerScenarios":"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}}`).","commonSituations":"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.","solutions":["Reduce to at most two arguments: `{{indent 4 .Text}}` or `{{indent .Text}}`.","If piping, use `{{.Text | indent 4}}` and do not also pass the text positionally.","Remove duplicate/leftover arguments left from template refactoring; verify against FuncHelp usage."],"exampleFix":"// before\n{{ indent 2 4 .ProvisionScript }}\n// after\n{{ indent 4 .ProvisionScript }}","handlingStrategy":"validation","validationCode":"// template-level check: at most size + text\n// {{ indent 4 .Text }}  // OK\n// Go-side guard for generated pipelines:\nif len(args) > 2 { return errors.New(\"indent: too many arguments\") }","typeGuard":"func indentArityOk(n int) bool { return n >= 1 && n <= 2 }","tryCatchPattern":"b, err := textutil.ExecuteTemplate(tmpl, data)\nif err != nil {\n    if strings.Contains(err.Error(), \"function takes at most 2 arguments\") {\n        return fmt.Errorf(\"indent called with extra arguments in template: %w\", err)\n    }\n    return err\n}","preventionTips":["Never combine pipe input with a positional text argument; use `{{.Text | indent 4}}`.","Pass at most an int size plus one string.","After refactoring templates, grep for `indent` calls and check argument counts.","Keep one canonical helper snippet per indent use-case to avoid signature drift."],"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"}