{"record":{"id":"b3f29c44028c01ce","repo":"nats-io/nats-server","slug":"bad-account","errorCode":null,"errorMessage":"bad account","messagePattern":"bad account","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":105,"sourceCode":"\tErrClientConnectedToLeafNodePort = errors.New(\"attempted to connect to leaf node port\")\n\n\t// ErrLeafNodeHasSameClusterName represents an error condition when a leafnode is a cluster\n\t// and it has the same cluster name as the hub cluster.\n\tErrLeafNodeHasSameClusterName = errors.New(\"remote leafnode has same cluster name\")\n\n\t// ErrLeafNodeDisabled is when we disable leafnodes.\n\tErrLeafNodeDisabled = errors.New(\"leafnodes disabled\")\n\n\t// ErrConnectedToWrongPort represents an error condition when a connection is attempted\n\t// to the wrong listen port (for instance a LeafNode to a client port, etc...)\n\tErrConnectedToWrongPort = errors.New(\"attempted to connect to wrong port\")\n\n\t// ErrAccountExists is returned when an account is attempted to be registered\n\t// but already exists.\n\tErrAccountExists = errors.New(\"account exists\")\n\n\t// ErrBadAccount represents a malformed or incorrect account.\n\tErrBadAccount = errors.New(\"bad account\")\n\n\t// ErrReservedAccount represents a reserved account that can not be created.\n\tErrReservedAccount = errors.New(\"reserved account\")\n\n\t// ErrMissingAccount is returned when an account does not exist.\n\tErrMissingAccount = errors.New(\"account missing\")\n\n\t// ErrMissingService is returned when an account does not have an exported service.\n\tErrMissingService = errors.New(\"service missing\")\n\n\t// ErrBadServiceType is returned when latency tracking is being applied to non-singleton response types.\n\tErrBadServiceType = errors.New(\"bad service response type\")\n\n\t// ErrBadSampling is returned when the sampling for latency tracking is not 1 >= sample <= 100.\n\tErrBadSampling = errors.New(\"bad sampling percentage, should be 1-100\")\n\n\t// ErrAccountValidation is returned when an account has failed validation.\n\tErrAccountValidation = errors.New(\"account validation failed\")","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L87-L123","documentation":"ErrBadAccount is returned by client.registerWithAccount when the supplied Account is nil, or when the account is marked bad (e.g. it is being deleted or failed validation checks under acc.mu). The client cannot register with such an account and subscription setup fails.","triggerScenarios":"Calling client registerWithAccount (directly or via subscription setup) with a nil *Account; attaching a client to an account that was concurrently removed from the server or flagged invalid; internal paths where an account lookup returned an account that failed integrity checks.","commonSituations":"Embedded-NATS code passing a nil account into internal APIs; client connecting right as the account is deleted via resolver updates; race between account removal and client (re)authentication.","solutions":["Ensure the account is fetched from the server (s.LookupAccount) and is non-nil before registering clients","Verify the account still exists and is not slated for deletion before use","Re-authenticate the client against a valid account; check resolver/JWT config so accounts resolve correctly"],"exampleFix":"// before\nacc, _ := s.LookupAccount(name)\nc.registerWithAccount(acc) // acc may be nil\n// after\nacc, err := s.LookupAccount(name)\nif err != nil || acc == nil { return fmt.Errorf(\"account %q not available\", name) }\nreturn c.registerWithAccount(acc)","handlingStrategy":"type-guard","validationCode":"acc, err := s.LookupAccount(name)\nif err != nil || acc == nil { return fmt.Errorf(\"account %q unavailable\", name) }","typeGuard":"func accountUsable(a *server.Account) bool { return a != nil }","tryCatchPattern":"if err := c.RegisterWithAccount(acc); err != nil {\n    if errors.Is(err, server.ErrBadAccount) { /* refetch account, re-auth client */ }\n    return err\n}","preventionTips":["Never ignore errors from account lookup/creation","Check errors.Is on the account's removal before reuse","Re-fetch accounts after resolver/JWT updates"],"tags":["nats","account","nil-check"],"backgroundTag":"invalid-account-reference","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}