nats-io/nats-server · error
account missing
Error message
account missing
What it means
ErrMissingAccount is returned when an Account method that requires a receiver account is called on a nil *Account. Functions like AddServiceExport (accounts.go:1222), TrackServiceExportWithSampling (accounts.go:1274), AddServiceImport, AddStreamExport and related mapping APIs all begin with `if a == nil { return ErrMissingAccount }`, because exports/imports cannot be configured on a non-existent account.
Source
Thrown at server/errors.go:111
// ErrLeafNodeDisabled is when we disable leafnodes.
ErrLeafNodeDisabled = errors.New("leafnodes disabled")
// ErrConnectedToWrongPort represents an error condition when a connection is attempted
// to the wrong listen port (for instance a LeafNode to a client port, etc...)
ErrConnectedToWrongPort = errors.New("attempted to connect to wrong port")
// ErrAccountExists is returned when an account is attempted to be registered
// but already exists.
ErrAccountExists = errors.New("account exists")
// ErrBadAccount represents a malformed or incorrect account.
ErrBadAccount = errors.New("bad account")
// ErrReservedAccount represents a reserved account that can not be created.
ErrReservedAccount = errors.New("reserved account")
// ErrMissingAccount is returned when an account does not exist.
ErrMissingAccount = errors.New("account missing")
// ErrMissingService is returned when an account does not have an exported service.
ErrMissingService = errors.New("service missing")
// ErrBadServiceType is returned when latency tracking is being applied to non-singleton response types.
ErrBadServiceType = errors.New("bad service response type")
// ErrBadSampling is returned when the sampling for latency tracking is not 1 >= sample <= 100.
ErrBadSampling = errors.New("bad sampling percentage, should be 1-100")
// ErrAccountValidation is returned when an account has failed validation.
ErrAccountValidation = errors.New("account validation failed")
// ErrAccountExpired is returned when an account has expired.
ErrAccountExpired = errors.New("account expired")
// ErrNoAccountResolver is returned when we attempt an update but do not have an account resolver.
ErrNoAccountResolver = errors.New("account resolver missing")View on GitHub (pinned to 3a66a489d2)
Solutions
- Check the error from s.LookupAccount / account creation before using the returned *Account
- Guard account configuration code with a nil check on the account
- Fix the account name or ensure the account is registered before configuring exports/imports
Example fix
// before
acc, _ := s.LookupAccount("svc")
acc.AddServiceExport("req", nil) // panics/returns ErrMissingAccount if acc is nil
// after
acc, err := s.LookupAccount("svc")
if err != nil { return err }
if err := acc.AddServiceExport("req", nil); err != nil { return err } Defensive patterns
Strategy: type-guard
Validate before calling
acc, err := s.LookupAccount(name)
if err != nil { return err }
if acc == nil { return fmt.Errorf("account %q not found", name) } Type guard
func hasAccount(a *server.Account) bool { return a != nil } Try / catch
if err := acc.AddServiceExport(subj, nil); err != nil {
if errors.Is(err, server.ErrMissingAccount) { /* account was nil: fix lookup */ }
return err
} Prevention
- Always propagate errors from LookupAccount instead of discarding them
- Nil-check accounts before configuring exports/imports
- Re-run mapping configuration after account re-registration
When it happens
Trigger: Calling a.AddServiceExport(...), a.TrackServiceExport(...), a.AddServiceImport(...), a.AddStreamExport(...) or a.AddMapping-style APIs where a is a nil *Account — usually because an earlier LookupAccount failed and its error was ignored. Also reported from test paths like TestCrossAccountRequestReply when account setup silently failed.
Common situations: Embedded-NATS setup code that ignores the error from LookupAccount/RegisterAccount and then configures mappings on the nil account; typos in account names at bootstrap; accounts removed by resolver updates before mapping configuration runs.
Related errors
- bad account
- account exists
- reserved account
- account jwt not found
- auth callout violation: auth callout response is not for exp
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/5b1d0e11c4592c4b.
Report an issue: GitHub.