{"record":{"id":"46fa4176e3b6216d","repo":"nats-io/nats-server","slug":"gateway-has-no-name","errorCode":null,"errorMessage":"gateway has no name","messagePattern":"gateway has no name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/gateway.go","lineNumber":311,"sourceCode":"\t}\n\tclone := &RemoteGatewayOpts{\n\t\tName: r.Name,\n\t\tURLs: deepCopyURLs(r.URLs),\n\t}\n\tif r.TLSConfig != nil {\n\t\tclone.TLSConfig = r.TLSConfig.Clone()\n\t\tclone.TLSTimeout = r.TLSTimeout\n\t}\n\treturn clone\n}\n\n// Ensure that gateway is properly configured.\nfunc validateGatewayOptions(o *Options) error {\n\tif o.Gateway.Name == _EMPTY_ && o.Gateway.Port == 0 {\n\t\treturn nil\n\t}\n\tif o.Gateway.Name == _EMPTY_ {\n\t\treturn errors.New(\"gateway has no name\")\n\t}\n\tif strings.Contains(o.Gateway.Name, \" \") {\n\t\treturn ErrGatewayNameHasSpaces\n\t}\n\tif o.Gateway.Port == 0 {\n\t\treturn fmt.Errorf(\"gateway %q has no port specified (select -1 for random port)\", o.Gateway.Name)\n\t}\n\tfor i, g := range o.Gateway.Gateways {\n\t\tif g.Name == _EMPTY_ {\n\t\t\treturn fmt.Errorf(\"gateway in the list %d has no name\", i)\n\t\t}\n\t\tif len(g.URLs) == 0 {\n\t\t\treturn fmt.Errorf(\"gateway %q has no URL\", g.Name)\n\t\t}\n\t}\n\tif err := validatePinnedCerts(o.Gateway.TLSPinnedCerts); err != nil {\n\t\treturn fmt.Errorf(\"gateway %q: %v\", o.Gateway.Name, err)\n\t}","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/gateway.go#L293-L329","documentation":"The 'gateway has no name' error comes from validateGatewayOptions in server/gateway.go: it is returned when gateway options enable a gateway (non-zero Port) but leave Gateway.Name empty. Gateways need a unique cluster name to identify the gateway cluster during connections, so starting the server with a port but no name is a configuration error.","triggerScenarios":"Config sets gateway { port: N } (or -P gateway flag / Gateway.Port != 0) but omits gateway.name; validateOptions calls validateGatewayOptions which rejects empty names at startup. Note: name AND port both empty is allowed (gateways disabled).","commonSituations":"Adding a gateway port to a config that previously had no gateway section and forgetting the name field; templated configs where the name variable is empty; copy of a config stripped of the name.","solutions":["Add gateway { name: \"<cluster-name>\" } to the server config next to the port.","Or set o.Gateway.Name in code before nats-server validates options.","If gateways are not intended, remove the gateway port setting so both name and port are empty (gateways disabled)."],"exampleFix":"// before\ngateway {\n  port: 7222\n}\n// after\ngateway {\n  name: \"A\"\n  port: 7222\n}","handlingStrategy":"validation","validationCode":"if o.Gateway.Port != 0 && o.Gateway.Name == \"\" {\n    return errors.New(\"gateway port set but gateway.name missing\")\n}","typeGuard":null,"tryCatchPattern":"if err := validateGatewayOptions(opts); err != nil {\n    if strings.Contains(err.Error(), \"gateway has no name\") {\n        log.Fatal(\"add gateway.name to config\")\n    }\n}","preventionTips":["Always pair gateway.port with gateway.name in config templates.","Validate config with nats-server --test before startup.","Ensure template variables for gateway.name are non-empty."],"tags":["nats","gateway","configuration","startup"],"backgroundTag":"missing-config-field","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}