{"record":{"id":"5b1d0e11c4592c4b","repo":"nats-io/nats-server","slug":"account-missing","errorCode":null,"errorMessage":"account missing","messagePattern":"account missing","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":111,"sourceCode":"\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\")\n\n\t// ErrAccountExpired is returned when an account has expired.\n\tErrAccountExpired = errors.New(\"account expired\")\n\n\t// ErrNoAccountResolver is returned when we attempt an update but do not have an account resolver.\n\tErrNoAccountResolver = errors.New(\"account resolver missing\")","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L93-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nacc, _ := s.LookupAccount(\"svc\")\nacc.AddServiceExport(\"req\", nil) // panics/returns ErrMissingAccount if acc is nil\n// after\nacc, err := s.LookupAccount(\"svc\")\nif err != nil { return err }\nif err := acc.AddServiceExport(\"req\", nil); err != nil { return err }","handlingStrategy":"type-guard","validationCode":"acc, err := s.LookupAccount(name)\nif err != nil { return err }\nif acc == nil { return fmt.Errorf(\"account %q not found\", name) }","typeGuard":"func hasAccount(a *server.Account) bool { return a != nil }","tryCatchPattern":"if err := acc.AddServiceExport(subj, nil); err != nil {\n    if errors.Is(err, server.ErrMissingAccount) { /* account was nil: fix lookup */ }\n    return err\n}","preventionTips":["Always propagate errors from LookupAccount instead of discarding them","Nil-check accounts before configuring exports/imports","Re-run mapping configuration after account re-registration"],"tags":["nats","account","nil-check","service-export"],"backgroundTag":"missing-account","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}