{"record":{"id":"de7f880a3ebaa8c5","repo":"nats-io/nats-server","slug":"expected-port-or-host-port-got-t","errorCode":null,"errorMessage":"expected port or host:port, got %T","messagePattern":"expected port or host:port, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/opts.go","lineNumber":2012,"sourceCode":"// 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)\n\tcm, ok := v.(map[string]any)\n\tif !ok {\n\t\treturn &configErr{tk, fmt.Sprintf(\"Expected map to define cluster, got %T\", v)}\n\t}\n\n\tfor mk, mv := range cm {\n\t\t// Again, unwrap token value if line check is required.\n\t\ttk, mv = unwrapValue(mv, &lt)","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/opts.go#L1994-L2030","documentation":"The address parser accepts only int64 (a bare port) or string (host:port) config values; any other YAML/JSON type hits the default branch and produces this error including the Go type of the offending value. It tells you the config key for the address was provided as an unsupported type (bool, float, array, map, null).","triggerScenarios":"Values like listen: true, listen: 4222.0 (parsed as float64), listen: [4222], or listen: null in the config file — anything not an integer or string.","commonSituations":"YAML interpreting 4222.0 as a float; inconsistent quoting; passing a list of addresses where one string is expected; empty value rendered as null by templating.","solutions":["Quote the value to force a string: listen: \"0.0.0.0:4222\".","Remove a trailing .0 or decimals so YAML parses a plain integer, or quote it: \"4222\".","Replace arrays/maps/null with a single host:port string value.","Read the %T in the message (e.g. float64, bool, []interface {}) to identify exactly which type YAML produced and adjust."],"exampleFix":"// before\nlisten: 4222.0\n// after\nlisten: 4222","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isAddressValue(v any) bool {\n\tswitch t := v.(type) {\n\tcase int64:\n\t\treturn t > 0 && t <= 65535\n\tcase string:\n\t\t_, _, err := net.SplitHostPort(t)\n\t\treturn err == nil\n\t}\n\treturn false\n}","tryCatchPattern":null,"preventionTips":["Quote address values in YAML to force string type.","Avoid floats/decimals for ports (4222.0 parses as float64).","Never assign arrays/maps/null to address options."],"tags":["config","type-mismatch","address"],"backgroundTag":"config-value-wrong-type","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}