{"record":{"id":"be7d4f53ee7464c8","repo":"hashicorp/nomad","slug":"error-determining-port-v","errorCode":null,"errorMessage":"error determining port: %v","messagePattern":"error determining port: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_api.go","lineNumber":335,"sourceCode":"\t}\n\n\tif c.body != nil {\n\t\tparts = append(parts, \"--data-binary @-\")\n\t}\n\n\tif config.URL().EscapedPath() != \"\" {\n\t\tparts = append(parts, fmt.Sprintf(\"--unix-socket %q\", config.URL().EscapedPath()))\n\t}\n\n\tif config.TLSConfig != nil {\n\t\tparts = tlsToCurl(parts, config.TLSConfig)\n\n\t\t// If a TLS server name is set we must alter the URL and use\n\t\t// curl's --connect-to flag.\n\t\tif v := config.TLSConfig.TLSServerName; v != \"\" {\n\t\t\tpathHost, port, err := net.SplitHostPort(path.Host)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"error determining port: %v\", err)\n\t\t\t}\n\n\t\t\t// curl uses the url for SNI so override it with the\n\t\t\t// configured server name\n\t\t\tpath.Host = net.JoinHostPort(v, port)\n\n\t\t\t// curl uses --connect-to to allow specifying a\n\t\t\t// different connection address for the hostname in the\n\t\t\t// path. The format is:\n\t\t\t//   logical-host:logical-port:actual-host:actual-port\n\t\t\t// Ports will always match since only the hostname is\n\t\t\t// overridden for SNI.\n\t\t\tparts = append(parts, fmt.Sprintf(`--connect-to \"%s:%s:%s:%s\"`,\n\t\t\t\tv, port, pathHost, port))\n\t\t}\n\t}\n\n\t// Add headers","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_api.go#L317-L353","documentation":"apiToCurl builds an equivalent curl command for `nomad operator api`. When a TLSServerName is configured, it splits the URL host with net.SplitHostPort to rewire the host for curl's --connect-to flag; if the host component is not in host:port form (or is malformed), SplitHostPort fails and the error is surfaced as \"error determining port: %v\".","triggerScenarios":"`nomad operator api <path>` with a client config that sets tls.server_name (or NOMAD_CACERT/TLS server name) and an Address/URL whose host part lacks a port or contains malformed brackets, e.g. `https://nomad.example.com/path` without an explicit port or a bare IPv6 string without brackets.","commonSituations":"Address configured without :port while TLSServerName set; mis-entered IPv6 address missing brackets; environment variable NOMAD_ADDR containing a path or extra characters; config file mixing TLS options with a non-authority URL.","solutions":["Include an explicit port in NOMAD_ADDR/config.Address (e.g. https://host:4646).","Wrap IPv6 hosts in brackets: http://[::1]:4646.","Remove stray path/scheme characters from the address so url.Parse yields a clean Host.","If you don't need SNI override, unset tls.server_name."],"exampleFix":"// before (shell)\nNOMAD_ADDR=https://nomad.internal nomad operator api /v1/health   # TLSServerName set, no port\n// after\nNOMAD_ADDR=https://nomad.internal:4647 nomad operator api /v1/health","handlingStrategy":"validation","validationCode":"// shell: ensure address has host:port before operator api\ncase \"$(echo \"$NOMAD_ADDR\" | sed -E 's#^https?://([^/]+)/?.*#\\1#')\" in\n  *:*) : ;;  # ok\n  *) echo \"NOMAD_ADDR must include an explicit port when tls.server_name is set\"; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":"// bash\nif ! out=$(nomad operator api /v1/health 2>&1); then\n  case \"$out\" in *\"error determining port\"*) echo \"fix NOMAD_ADDR host:port\" ;; esac\nfi","preventionTips":["Always set explicit ports in NOMAD_ADDR (e.g. :4646/:4647).","Bracket IPv6 literals in addresses.","Keep addresses as bare origin URLs (scheme://host:port) with no trailing path/junk."],"tags":["cli","nomad","curl","url-parsing","tls"],"backgroundTag":"invalid-url","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}