{"record":{"id":"a2496c13464b16c0","repo":"caddyserver/caddy","slug":"unflagged-argument-s-is-overridden-by-flags","errorCode":null,"errorMessage":"unflagged argument \\\"%s\\\" is overridden by flags","messagePattern":"unflagged argument \\\\\"(.+?)\\\\\" is overridden by flags","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/staticresp.go","lineNumber":342,"sourceCode":"\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 {\n\t\t\tif argInt >= 100 && argInt <= 999 {\n\t\t\t\tstatusCode = argInt\n\t\t\t}\n\t\t} else if body == \"\" {\n\t\t\tbody = arg\n\t\t}\n\t}\n\n\t// if we still need a body, see if stdin is being piped\n\tif body == \"\" {\n\t\tstdinInfo, err := os.Stdin.Stat()\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, err\n\t\t}","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/staticresp.go#L324-L360","documentation":"'caddy respond' rejects the invocation when a positional argument is supplied together with both an explicit --status flag and a non-empty --body flag, since the argument would be silently ignored. The %q shows the redundant argument. This guards against ambiguity where the user believes their argument took effect.","triggerScenarios":"caddy respond \"hi\" --status 404 --body \"bye\" — positional \"hi\" plus both flags set; statusCodeFlagSpecified is true and bodyFl non-empty.","commonSituations":"Scripts evolved over time where an old positional argument was left alongside newly added flags; refactoring command invocations.","solutions":["Remove the redundant positional argument","Or drop --status/--body flags and let the argument carry the value","Audit scripts that call 'caddy respond' for duplicated value sources"],"exampleFix":"# before\ncaddy respond \"hi\" --status 404 --body \"bye\"\n\n# after\ncaddy respond --status 404 --body \"bye\"","handlingStrategy":"validation","validationCode":"if positionalArg != \"\" && bodyFlag != \"\" && statusFlagSet {\n    return errors.New(\"remove the redundant positional argument or the --status/--body flags\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one style (positional or flags) per invocation, not both","Clean up legacy positional args when adding flags to scripts"],"tags":["caddy","cli","respond","flag-conflict"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}