{"record":{"id":"54b8e15451d9194b","repo":"lima-vm/lima","slug":"invalid-port-forward-format-q-expected-host-gue","errorCode":null,"errorMessage":"invalid port forward format %#q, expected HOST:GUEST or HOST:GUEST,static=true","messagePattern":"invalid port forward format %#q, expected HOST:GUEST or HOST:GUEST,static=true","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/editflags/editflags.go","lineNumber":142,"sourceCode":"\tflags.StringArray(\"port-forward\", nil, commentPrefix+\"Port forwards (host:guest), e.g., '8080:80' or '9090:9090,static=true' for static port-forwards\")\n\t_ = cmd.RegisterFlagCompletionFunc(\"port-forward\", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {\n\t\treturn []string{\"8080:80\", \"3000:3000\", \"8080:80,static=true\"}, cobra.ShellCompDirectiveNoFileComp\n\t})\n\n\tflags.String(\"audio-device\", \"\", commentPrefix+\"Audio device backend (e.g., 'pa', 'coreaudio', 'none')\")\n\tflags.String(\"audio-interface\", \"\", commentPrefix+\"Audio virtual hardware interface ('hda' or 'virtio')\")\n}\n\nfunc defaultExprFunc(expr string) func(v *flag.Flag) ([]string, error) {\n\treturn func(v *flag.Flag) ([]string, error) {\n\t\treturn []string{fmt.Sprintf(expr, v.Value)}, nil\n\t}\n}\n\nfunc ParsePortForward(spec string) (hostPort, guestPort string, isStatic bool, err error) {\n\tparts := strings.Split(spec, \",\")\n\tif len(parts) > 2 {\n\t\treturn \"\", \"\", false, fmt.Errorf(\"invalid port forward format %#q, expected HOST:GUEST or HOST:GUEST,static=true\", spec)\n\t}\n\n\tportParts := strings.Split(strings.TrimSpace(parts[0]), \":\")\n\tif len(portParts) != 2 {\n\t\treturn \"\", \"\", false, fmt.Errorf(\"invalid port forward format %#q, expected HOST:GUEST\", parts[0])\n\t}\n\n\thostPort = strings.TrimSpace(portParts[0])\n\tguestPort = strings.TrimSpace(portParts[1])\n\n\tif len(parts) == 2 {\n\t\tstaticPart := strings.TrimSpace(parts[1])\n\t\tif staticValue, ok := strings.CutPrefix(staticPart, \"static=\"); ok {\n\t\t\tisStatic, err = strconv.ParseBool(staticValue)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", \"\", false, fmt.Errorf(\"invalid value for static parameter: %#q\", staticValue)\n\t\t\t}\n\t\t} else {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/editflags/editflags.go#L124-L160","documentation":"Thrown by `ParsePortForward` in cmd/limactl/editflags when a port-forward spec supplied for `limactl edit --set` (e.g. via port-forward flags) contains more than one comma-separated segment. The accepted forms are `HOST:GUEST` or `HOST:GUEST,static=true`; anything with two or more commas (three+ parts) is rejected with the full spec quoted via `%#q`.","triggerScenarios":"Calling `BuildPortForwardExpression` (used by `limactl edit --set`) with a spec like `8080:80,static=true,proto=tcp` or `\"127.0.0.1:8080:80,static=true\"` — i.e. more than one comma — or passing extra options that older/experimental syntax allowed.","commonSituations":"Users copying port-forward options from lima.yaml (which supports more keys like `proto`, `reverse`, `ignore`) into the CLI spec; accidentally quoting the host:guest as one field; typos adding stray commas.","solutions":["Reduce the spec to at most one comma: `HOST:GUEST` or `HOST:GUEST,static=true`.","Move unsupported options (proto, reverse, ignore) into the instance YAML's `portForwards` section via the editor instead of the `--set` spec.","Check for accidental double colons or extra commas: `127.0.0.1:8080:80` belongs in YAML config, not the CLI spec.","Run `limactl edit --help` to confirm the exact accepted syntax for your lima version."],"exampleFix":"// before\nlimactl edit myvm --set '.portForwards += ...' --port-forward '8080:80,static=true,proto=tcp'\n\n// after\nlimactl edit myvm --port-forward '8080:80,static=true'   # proto etc. go in the YAML config","handlingStrategy":"validation","validationCode":"// Validate a port-forward spec before passing it to limactl:\nfunc validPortForwardSpec(spec string) bool {\n    parts := strings.Split(spec, \",\")\n    if len(parts) > 2 { return false }\n    return len(strings.Split(strings.TrimSpace(parts[0]), \":\")) == 2 &&\n           (len(parts) == 1 || parts[1] == \"static=true\")\n}","typeGuard":null,"tryCatchPattern":"if err := runCmd(\"limactl\", \"edit\", inst, \"--port-forward\", spec); err != nil {\n    if strings.Contains(err.Error(), \"invalid port forward format\") {\n        return fmt.Errorf(\"spec %q rejected: use HOST:GUEST or HOST:GUEST,static=true\", spec)\n    }\n    return err\n}","preventionTips":["Only use the two documented forms: HOST:GUEST and HOST:GUEST,static=true.","Put advanced options (proto, reverse, ignore, hostIP) in the YAML portForwards section, not the CLI spec.","Shell-quote specs containing commas so the flag receives a single argument."],"tags":["port-forward","cli","argument-parsing","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}