{"record":{"id":"00e968c20a4a4aef","repo":"nats-io/nats-server","slug":"could-not-parse-address-string-q","errorCode":null,"errorMessage":"could not parse address string %q","messagePattern":"could not parse address string %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/opts.go","lineNumber":2004,"sourceCode":"}\n\n// hostPort is simple struct to hold parsed listen/addr strings.\ntype hostPort struct {\n\thost string\n\tport int\n}\n\n// parseListen will parse listen option which is replacing host/net and port\nfunc parseListen(v any) (*hostPort, error) {\n\thp := &hostPort{}\n\tswitch vv := v.(type) {\n\t// Only a port\n\tcase int64:\n\t\thp.port = int(vv)\n\tcase string:\n\t\thost, port, err := net.SplitHostPort(vv)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not parse address string %q\", vv)\n\t\t}\n\t\thp.port, err = strconv.Atoi(port)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not parse port %q\", port)\n\t\t}\n\t\thp.host = host\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"expected port or host:port, got %T\", vv)\n\t}\n\treturn hp, nil\n}\n\n// parseCluster will parse the cluster config.\nfunc parseCluster(v any, opts *Options, errors *[]error, warnings *[]error) error {\n\tvar lt token\n\tdefer convertPanicToErrorList(&lt, errors)\n\n\ttk, v := unwrapValue(v, &lt)","sourceCodeStart":1986,"sourceCodeEnd":2022,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/opts.go#L1986-L2022","documentation":"This error comes from the address parsing helper in server/opts.go when a config value given as a string cannot be split into host and port by net.SplitHostPort. The library expects either an integer port or a 'host:port' string; a string in any other form is rejected with this message. Parsing aborts and the error is added to the config errors list.","triggerScenarios":"Setting listen/cluster/gateway/monitor addresses in the config as a string like 'nats://host', 'host:', 'localhost' (no port), or a malformed IPv6 literal, so SplitHostPort fails.","commonSituations":"Omitting the port ('listen: 0.0.0.0'); using a full URL instead of host:port ('listen: nats://0.0.0.0:4222'); unbalanced brackets in IPv6 literals; whitespace from templating.","solutions":["Change the value to a plain 'host:port' string, e.g. '0.0.0.0:4222'.","Use just an integer if you only want a port on the default host, e.g. 4222.","For IPv6, wrap the host in brackets with a port: '[::1]:4222'.","Print the exact offending string from the error (%q) and check for hidden whitespace or stray characters."],"exampleFix":"// before\nlisten: nats://0.0.0.0:4222\n// after\nlisten: 0.0.0.0:4222","handlingStrategy":"validation","validationCode":"// validate the address string before writing it into the config\nif _, _, err := net.SplitHostPort(addr); err != nil {\n\treturn fmt.Errorf(\"invalid address %q: use host:port\", addr)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always specify addresses as host:port, never bare host or full URL.","Bracket IPv6 hosts: [::1]:4222.","Trim whitespace/env output before inserting into config."],"tags":["config","address","parsing"],"backgroundTag":"invalid-address-format","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}