{"record":{"id":"3f6eb12f62215bff","repo":"caddyserver/caddy","slug":"invalid-to-flag-v","errorCode":null,"errorMessage":"invalid to flag: %v","messagePattern":"invalid to flag: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/reverseproxy/command.go","lineNumber":103,"sourceCode":"}\n\nfunc cmdReverseProxy(fs caddycmd.Flags) (int, error) {\n\tcaddy.TrapSignals()\n\n\tfrom := fs.String(\"from\")\n\tchangeHost := fs.Bool(\"change-host-header\")\n\tinsecure := fs.Bool(\"insecure\")\n\tdisableRedir := fs.Bool(\"disable-redirects\")\n\tinternalCerts := fs.Bool(\"internal-certs\")\n\taccessLog := fs.Bool(\"access-log\")\n\tdebug := fs.Bool(\"debug\")\n\n\thttpPort := strconv.Itoa(caddyhttp.DefaultHTTPPort)\n\thttpsPort := strconv.Itoa(caddyhttp.DefaultHTTPSPort)\n\n\tto, err := fs.GetStringSlice(\"to\")\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"invalid to flag: %v\", err)\n\t}\n\tif len(to) == 0 {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"--to is required\")\n\t}\n\n\t// set up the downstream address; assume missing information from given parts\n\tfromAddr, err := httpcaddyfile.ParseAddress(from)\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"invalid downstream address %s: %v\", from, err)\n\t}\n\tif fromAddr.Path != \"\" {\n\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"paths are not allowed: %s\", from)\n\t}\n\tif fromAddr.Scheme == \"\" {\n\t\tif fromAddr.Port == httpPort || fromAddr.Host == \"\" {\n\t\t\tfromAddr.Scheme = \"http\"\n\t\t} else {\n\t\t\tfromAddr.Scheme = \"https\"","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/reverseproxy/command.go#L85-L121","documentation":"The 'caddy reverse-proxy' quick-start command failed to read the --to flag via fs.GetStringSlice. This only happens if the flag value cannot be interpreted as a string slice — in practice a flagparse/runtime issue, since string flags rarely fail — and the raw error is appended.","triggerScenarios":"Passing --to in a form the flag package rejects (e.g. repeated incompatible definitions via a custom flag set) when invoking 'caddy reverse-proxy --from ... --to ...'.","commonSituations":"Shell-level mangling of the command line, or a wrapper script redefining flags; most users will never see this because malformed --to values parse fine and fail later.","solutions":["Re-run the command with a simple quoted --to value: caddy reverse-proxy --from localhost --to 'localhost:8080'.","Check for stray shell expansion (unquoted braces, globbing) around the --to argument.","If it persists, report the wrapped '%v' error — it indicates a flag-registration bug rather than bad input."],"exampleFix":"# before\ncaddy reverse-proxy --from example.com --to backend:8080 backend:8081\n\n# after\ncaddy reverse-proxy --from example.com --to backend:8080,backend:8081","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"to, err := fs.GetStringSlice(\"to\")\nif err != nil {\n    // this path is nearly unreachable; treat as a tooling bug and surface the raw error\n    return fmt.Errorf(\"reading --to flag: %w\", err)\n}","preventionTips":["Quote --to values to protect them from shell expansion.","Keep the CLI invocation in a script under version control rather than retyping flags.","Prefer a Caddyfile for anything beyond quick tests."],"tags":["cli","reverse-proxy","flags","startup"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}