{"record":{"id":"e74793d563f8b656","repo":"hashicorp/nomad","slug":"invalid-address-s-v","errorCode":null,"errorMessage":"invalid address '%s': %v","messagePattern":"invalid address '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/api.go","lineNumber":524,"sourceCode":"}\n\n// NewClient returns a new client\nfunc NewClient(config *Config) (*Client, error) {\n\tvar err error\n\t// bootstrap the config\n\tdefConfig := DefaultConfig()\n\n\tif config.Address == \"\" {\n\t\tconfig.Address = defConfig.Address\n\t}\n\n\t// we have to test the address that comes from DefaultConfig, because it\n\t// could be the value of NOMAD_ADDR which is applied without testing. But\n\t// only on the first use of this Config, otherwise we'll have mutated the\n\t// address\n\tif config.url == nil {\n\t\tif config.url, err = url.Parse(config.Address); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid address '%s': %v\", config.Address, err)\n\t\t}\n\t}\n\n\thttpClient := config.HttpClient\n\tif httpClient == nil {\n\t\tswitch {\n\t\tcase config.url.Scheme == \"unix\":\n\t\t\thttpClient = defaultUDSClient(config) // mutates config\n\t\tdefault:\n\t\t\thttpClient = defaultHttpClient()\n\t\t}\n\n\t\tif err := ConfigureTLS(httpClient, config.TLSConfig); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tclient := &Client{","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/api/api.go#L506-L542","documentation":"In api/api.go:524, NewClient parses Config.Address with net/url.Parse before first use (also testing NOMAD_ADDR-derived defaults). If the address string is not a valid URL, NewClient fails with this error wrapping the url.Parse message. It is a configuration error — the client never issues any request.","triggerScenarios":"Constructing api.NewClient(&api.Config{Address: \"...\"}) or setting NOMAD_ADDR to a string url.Parse rejects: control characters, malformed schemes (e.g. \"http://[bad-ipv6\"), stray spaces, or an empty/garbage value.","commonSituations":"NOMAD_ADDR exported with trailing whitespace or a typo; templating tools injecting multi-line values; concatenating host:port strings incorrectly; IPv6 addresses missing brackets.","solutions":["Read the wrapped %v message for the exact parse failure and fix the Address string","Ensure the address includes a scheme, e.g. http://127.0.0.1:4646 or https://nomad.example.com","Echo/inspect NOMAD_ADDR for whitespace, newlines, or stray characters; re-export it","Wrap IPv6 literals in square brackets: http://[::1]:4646","Validate the URL with url.Parse in your own bootstrap code before calling NewClient"],"exampleFix":"// before\ncfg.Address := os.Getenv(\"NOMAD_ADDR\") // \"http://nomad.internal :4646\"\nclient, err := api.NewClient(cfg) // invalid address\n// after\naddr := strings.TrimSpace(os.Getenv(\"NOMAD_ADDR\"))\nif _, err := url.Parse(addr); err != nil { return fmt.Errorf(\"bad NOMAD_ADDR %q: %w\", addr, err) }\ncfg.Address = addr","handlingStrategy":"validation","validationCode":"addr := strings.TrimSpace(os.Getenv(\"NOMAD_ADDR\"))\nif u, err := url.Parse(addr); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"NOMAD_ADDR must be a full URL like http://127.0.0.1:4646, got %q\", addr)\n}","typeGuard":"func validAddress(addr string) bool {\n\tu, err := url.Parse(addr)\n\treturn err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"client, err := api.NewClient(cfg)\nif err != nil && strings.Contains(err.Error(), \"invalid address\") {\n\treturn fmt.Errorf(\"check NOMAD_ADDR/Config.Address: %w\", err)\n}","preventionTips":["Always include scheme and host: http://host:4646","Trim env-derived addresses before use","Wrap IPv6 hosts in brackets","Validate NOMAD_ADDR at deploy time, not first client use"],"tags":["configuration","url","nomad-api"],"backgroundTag":"invalid-address","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"}