{"record":{"id":"c85b4c33d978db15","repo":"nats-io/nats-server","slug":"server-name-cannot-contain-spaces","errorCode":null,"errorMessage":"server name cannot contain spaces","messagePattern":"server name cannot contain spaces","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":178,"sourceCode":"\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\n\t// but they are not supported on this server.\n\tErrMsgHeadersNotSupported = errors.New(\"message headers not supported\")\n\n\t// ErrNoRespondersRequiresHeaders signals that a client needs to have headers\n\t// on if they want no responders behavior.\n\tErrNoRespondersRequiresHeaders = errors.New(\"no responders requires headers support\")\n\n\t// ErrClusterNameConfigConflict signals that the options for cluster name in cluster and gateway are in conflict.\n\tErrClusterNameConfigConflict = errors.New(\"cluster name conflicts between cluster and gateway definitions\")\n\n\t// ErrClusterNameRemoteConflict signals that a remote server has a different cluster name.\n\tErrClusterNameRemoteConflict = errors.New(\"cluster name from remote server conflicts\")\n","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L160-L196","documentation":"ErrServerNameHasSpaces signals that the configured server name contains a space, which NATS disallows because the server name appears in protocol messages and route/gateway identification. It is produced by config validation in server/opts.go:1159 as a configErr attached to the offending token, and tests assert ProcessConfigFile returns it (server_test.go:2400).","triggerScenarios":"Setting `server_name: \"my server\"` in the config file; `--name \"prod server\"` on the command line; hostname-derived names containing spaces (rare, but via templating/substitution).","commonSituations":"Templated configs where a display name with spaces is substituted into server_name; users naming servers after human-readable cluster labels.","solutions":["Replace spaces with dashes or underscores, e.g. `server_name: \"prod-server-01\"`.","If the name comes from a template/env var, sanitize it (tr -s ' ' '-') before rendering the config.","Rely on the hostname (default) or `hostport`-style names if unique display names are not required."],"exampleFix":"// before\nserver_name: \"prod server 01\"\n// after\nserver_name: \"prod-server-01\"","handlingStrategy":"validation","validationCode":"// Validate server_name before rendering/starting:\nif strings.ContainsAny(serverName, \" \") {\n    return fmt.Errorf(\"server_name %q must not contain spaces\", serverName)\n}","typeGuard":null,"tryCatchPattern":"if err := RunServer(opts); err != nil {\n    if errors.Is(err, ErrServerNameHasSpaces) {\n        // sanitize: strings.ReplaceAll(name, \" \", \"-\") and restart\n    }\n}","preventionTips":["Convention: server names use only [A-Za-z0-9-_].","Sanitize templated or env-derived names (region, hostname) before config render.","Run `nats-server -t` in CI/config pipelines to catch this early."],"tags":["nats","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"}