{"record":{"id":"f34c9296fcf0ba40","repo":"caddyserver/caddy","slug":"too-many-unflagged-arguments","errorCode":null,"errorMessage":"too many unflagged arguments","messagePattern":"too many unflagged arguments","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/staticresp.go","lineNumber":328,"sourceCode":"\t\tserver.Logs = new(ServerLogConfig)\n\t}\n\n\treturn server, nil\n}\n\nfunc cmdRespond(fl caddycmd.Flags) (int, error) {\n\tcaddy.TrapSignals()\n\n\t// get flag values\n\tlisten := fl.String(\"listen\")\n\tstatusCodeFl := fl.Int(\"status\")\n\tbodyFl := fl.String(\"body\")\n\taccessLog := fl.Bool(\"access-log\")\n\tdebug := fl.Bool(\"debug\")\n\targ := fl.Arg(0)\n\n\tif fl.NArg() > 1 {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"too many unflagged arguments\")\n\t}\n\n\t// prefer status and body from explicit flags\n\tstatusCode, body := statusCodeFl, bodyFl\n\n\t// figure out if status code was explicitly specified; this lets\n\t// us set a non-zero value as the default but is a little hacky\n\tstatusCodeFlagSpecified := slices.Contains(os.Args, \"--status\")\n\n\t// try to determine what kind of parameter the unnamed argument is\n\tif arg != \"\" {\n\t\t// specifying body and status flags makes the argument redundant/unused\n\t\tif bodyFl != \"\" && statusCodeFlagSpecified {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"unflagged argument \\\"%s\\\" is overridden by flags\", arg)\n\t\t}\n\n\t\t// if a valid 3-digit number, treat as status code; otherwise body\n\t\tif argInt, err := strconv.Atoi(arg); err == nil && !statusCodeFlagSpecified {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/staticresp.go#L310-L346","documentation":"CLI argument validation for 'caddy respond': at most one positional (unflagged) argument is allowed, which may be either a status code or the body. Passing two or more positional arguments returns ExitCodeFailedStartup with this error.","triggerScenarios":"Running e.g. 'caddy respond hello world' or 'caddy respond 200 \"ok\" extra' — the parser sees NArg() > 1 and rejects.","commonSituations":"Assuming respond takes body-then-status like other tools; copy-pasting multi-word bodies unquoted ('caddy respond hello world' instead of quoting).","solutions":["Quote multi-word bodies: caddy respond \"hello world\"","Pass status via flag: caddy respond --status 200 \"hello world\"","Use --body and --status flags instead of positional arguments entirely"],"exampleFix":"# before\ncaddy respond 200 hello world\n\n# after\ncaddy respond --status 200 --body \"hello world\"","handlingStrategy":"validation","validationCode":"// wrapper for scripts:\nargs := flag.Args()\nif len(args) > 1 {\n    return fmt.Errorf(\"pass at most one positional arg; quote the body: %v\", args)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always quote multi-word bodies in shell commands","Prefer explicit --status/--body flags in scripts for clarity"],"tags":["caddy","cli","respond","argument-validation"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}