{"id":"6085e5373b8db7ed","repo":"gohugoio/hugo","slug":"invalid-argument-to-command-t","errorCode":null,"errorMessage":"invalid argument to command: %T","messagePattern":"invalid argument to command: %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/hexec/exec.go","lineNumber":495,"sourceCode":"\tname               string\n\tfullyQualifiedName string\n\tenv                []string\n}\n\nfunc (c *commandeer) command(arg ...any) (*cmdWrapper, error) {\n\tif c == nil {\n\t\treturn nil, nil\n\t}\n\n\tvar args []string\n\tfor _, a := range arg {\n\t\tswitch v := a.(type) {\n\t\tcase string:\n\t\t\targs = append(args, v)\n\t\tcase func(*commandeer):\n\t\t\tv(c)\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"invalid argument to command: %T\", a)\n\t\t}\n\t}\n\n\tvar bin string\n\tif c.fullyQualifiedName != \"\" {\n\t\tbin = c.fullyQualifiedName\n\t} else {\n\t\tvar err error\n\t\tbin, err = exec.LookPath(c.name)\n\t\tif err != nil {\n\t\t\treturn nil, &NotFoundError{\n\t\t\t\tname:   c.name,\n\t\t\t\tmethod: \"in PATH\",\n\t\t\t}\n\t\t}\n\t}\n\n\touterr := &bytes.Buffer{}","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/common/hexec/exec.go#L477-L513","documentation":"Returned by commandeer.command in common/hexec/exec.go:495 when building an external command: each argument must be either a string (appended to argv) or a func(*commandeer) option (applied to configure stdio, dir, env, etc.). Any other Go type is rejected with its %T name. This is an internal API-contract error — it indicates a Hugo (or Hugo-embedding) caller passed a wrong-typed value into hexec, not a user configuration mistake.","triggerScenarios":"Calling Exec.New/Npx-style runners with an arg that is neither string nor func(*commandeer) — e.g. passing an int, []string, or fmt.Stringer directly instead of converting to string first.","commonSituations":"Development of Hugo itself or programs embedding hugolib that construct hexec commands; template-driven pipelines that somehow feed non-string args into an external command builder; regressions after refactoring argument plumbing.","solutions":["Convert every command argument to a string before passing it to the hexec command builder (e.g. cast numeric values with cast.ToString).","If passing options, ensure they are the func(*commandeer) option type (hexec.WithStdout, WithDir, etc.), not other structs.","If you hit this as an end user of stock Hugo, report it as a bug with the command/template that triggered it."],"exampleFix":"// before\nrunner, err := ex.command(\"--port\", 8080)\n\n// after\nrunner, err := ex.command(\"--port\", strconv.Itoa(8080))","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only strings and hexec option types are valid command args\nfunc validArg(a any) bool {\n    switch a.(type) {\n    case string, hexec.Option: // e.g. WithEnviron, WithStdout, WithDir\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["When calling hexec.Exec.New/Npx from code, pass args as strings and options via the provided With* helpers, never raw ints/structs","Convert values with fmt.Sprintf/strconv before appending to the arg list","Keep argument construction in one helper so the type contract is enforced in a single place"],"tags":["hugo","internal","api-contract","type-error","exec"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}