{"record":{"id":"216a2b3ec6e12edf","repo":"nats-io/nats-server","slug":"gateway-name-cannot-contain-spaces","errorCode":null,"errorMessage":"gateway name cannot contain spaces","messagePattern":"gateway name cannot contain spaces","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":165,"sourceCode":"\tErrServiceImportAuthorization = errors.New(\"service import not authorized\")\n\n\t// ErrImportFormsCycle is returned when an import would form a cycle.\n\tErrImportFormsCycle = errors.New(\"import forms a cycle\")\n\n\t// ErrCycleSearchDepth is returned when we have exceeded our maximum search depth..\n\tErrCycleSearchDepth = errors.New(\"search cycle depth exhausted\")\n\n\t// ErrClientOrRouteConnectedToGatewayPort represents an error condition when\n\t// a client or route attempted to connect to the Gateway port.\n\tErrClientOrRouteConnectedToGatewayPort = errors.New(\"attempted to connect to gateway port\")\n\n\t// ErrWrongGateway represents an error condition when a server receives a connect\n\t// request from a remote Gateway with a destination name that does not match the server's\n\t// Gateway's name.\n\tErrWrongGateway = errors.New(\"wrong gateway\")\n\n\t// ErrGatewayNameHasSpaces signals that the gateway name contains spaces, which is not allowed.\n\tErrGatewayNameHasSpaces = errors.New(\"gateway name cannot contain spaces\")\n\n\t// ErrNoSysAccount is returned when an attempt to publish or subscribe is made\n\t// when there is no internal system account defined.\n\tErrNoSysAccount = errors.New(\"system account not setup\")\n\n\t// ErrRevocation is returned when a credential has been revoked.\n\tErrRevocation = errors.New(\"credentials have been revoked\")\n\n\t// ErrServerNotRunning is used to signal an error that a server is not running.\n\tErrServerNotRunning = errors.New(\"server is not running\")\n\n\t// ErrServerNameHasSpaces signals that the server name contains spaces, which is not allowed.\n\tErrServerNameHasSpaces = errors.New(\"server name cannot contain spaces\")\n\n\t// ErrBadMsgHeader signals the parser detected a bad message header\n\tErrBadMsgHeader = errors.New(\"bad message header detected\")\n\n\t// ErrMsgHeadersNotSupported signals the parser detected a message header","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L147-L183","documentation":"ErrGatewayNameHasSpaces signals that the configured gateway name contains a space character, which NATS forbids because gateway names are used as protocol identifiers between clusters. It is returned by validateGatewayOptions (server/gateway.go:314) at startup and also surfaced as a configErr when parsing config files (server/opts.go:2290).","triggerScenarios":"Setting `gateway { name: \"my gateway\" }` in the server config; passing a gateway name with a space via flag/programmatic Options; config-file variable substitution producing a name with a space.","commonSituations":"Names copied from environment names like \"us east\" into config; interpolating `${REGION}` that contains spaces; hand-edited configs on multi-cluster deployments.","solutions":["Remove the space from the gateway name, e.g. use \"us-east\" or \"us_east\".","Quote/normalize environment variables used for gateway names before substitution.","Re-run the server; ProcessConfigFile will report the offending token via configErr if it remains."],"exampleFix":"// before\ngateway { name: \"us east\", port: 7222 }\n// after\ngateway { name: \"us-east\", port: 7222 }","handlingStrategy":"validation","validationCode":"// Validate the gateway name before rendering config:\nif strings.ContainsAny(gwName, \" \") || gwName == \"\" {\n    return fmt.Errorf(\"gateway name %q must not contain spaces\", gwName)\n}","typeGuard":null,"tryCatchPattern":"if err := RunServer(opts); err != nil {\n    if errors.Is(err, ErrGatewayNameHasSpaces) {\n        // normalize name: strings.ReplaceAll(name, \" \", \"-\") and retry\n    }\n}","preventionTips":["Convention: gateway names use only [A-Za-z0-9-_].","Sanitize environment-derived values substituted into gateway name fields.","Run `nats-server -t` (config test) in CI to catch validation errors pre-deploy."],"tags":["nats","gateway","config-validation","naming"],"backgroundTag":"invalid-config-value","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}