{"record":{"id":"b9380c8a54a57350","repo":"netbirdio/netbird","slug":"invalid-port-number-s","errorCode":null,"errorMessage":"invalid port number: %s","messagePattern":"invalid port number: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/cmd/expose.go","lineNumber":104,"sourceCode":"\t\tif p := u[i+1:]; p != \"\" {\n\t\t\treturn p\n\t\t}\n\t}\n\treturn strconv.FormatUint(uint64(fallback), 10)\n}\n\n// resolveExternalPort returns the effective external port, defaulting to the target port.\nfunc resolveExternalPort(targetPort uint64) uint16 {\n\tif exposeExternalPort != 0 {\n\t\treturn exposeExternalPort\n\t}\n\treturn uint16(targetPort)\n}\n\nfunc validateExposeFlags(cmd *cobra.Command, portStr string) (uint64, error) {\n\tport, err := strconv.ParseUint(portStr, 10, 32)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"invalid port number: %s\", portStr)\n\t}\n\tif port == 0 || port > 65535 {\n\t\treturn 0, fmt.Errorf(\"invalid port number: must be between 1 and 65535\")\n\t}\n\n\tif !isProtocolValid(exposeProtocol) {\n\t\treturn 0, fmt.Errorf(\"unsupported protocol %q: must be http, https, tcp, udp, or tls\", exposeProtocol)\n\t}\n\n\tif isClusterProtocol(exposeProtocol) {\n\t\tif exposePin != \"\" || exposePassword != \"\" || len(exposeUserGroups) > 0 {\n\t\t\treturn 0, fmt.Errorf(\"auth flags (--with-pin, --with-password, --with-user-groups) are not supported for %s protocol\", exposeProtocol)\n\t\t}\n\t} else if cmd.Flags().Changed(\"with-external-port\") {\n\t\treturn 0, fmt.Errorf(\"--with-external-port is not supported for %s protocol\", exposeProtocol)\n\t}\n\n\tif exposePin != \"\" && !pinRegexp.MatchString(exposePin) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/expose.go#L86-L122","documentation":"The positional port argument to `netbird expose <port>` failed strconv.ParseUint(portStr, 10, 32): it is not an unsigned base-10 number. validateExposeFlags rejects it before any daemon connection is made.","triggerScenarios":"Passing 'localhost:8080', 'tcp://host:5432', '8080/tcp', '-80', '0x1F90', '80 80', or an empty string (unset $PORT variable) as the port argument.","commonSituations":"Copy-pasting a URL or docker-style host:port spec instead of a bare port; scripts passing an unset variable; whitespace or a unit suffix sneaking into the value.","solutions":["Pass only the numeric local port: `netbird expose 8080`","Select the protocol with the flag, not the argument: `netbird expose --protocol tcp 5432`","In scripts, guard the value: `[[ \"$PORT\" =~ ^[0-9]+$ ]] || { echo \"bad port\"; exit 1; }`"],"exampleFix":"# before\nnetbird expose tcp://localhost:5432\n\n# after\nnetbird expose --protocol tcp 5432","handlingStrategy":"validation","validationCode":"portRe := regexp.MustCompile(`^[0-9]{1,5}$`)\nif !portRe.MatchString(portArg) {\n\tlog.Fatalf(\"%q is not a numeric port; pass only the bare port, e.g. `netbird expose 8080`\", portArg)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a bare decimal port, never host:port or a URL scheme","Select the protocol via --protocol, not by embedding it in the port argument","Guard variables in scripts before substitution: [[ \"$PORT\" =~ ^[0-9]+$ ]]"],"tags":["cli","validation","port","netbird-cli"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}