{"record":{"id":"fb57d8e36fe90e9f","repo":"nats-io/nats-server","slug":"filestore-is-nil","errorCode":null,"errorMessage":"filestore is nil","messagePattern":"filestore is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/filestore.go","lineNumber":13329,"sourceCode":"\tcfg     *FileConsumerInfo\n\tprf     keyGen\n\taek     cipher.AEAD\n\tname    string\n\todir    string\n\tifn     string\n\thh      *highwayhash.Digest64\n\tstate   ConsumerState\n\tfch     chan struct{}\n\tqch     chan struct{}\n\tflusher bool\n\twriting bool\n\tdirty   bool\n\tclosed  bool\n}\n\nfunc (fs *fileStore) ConsumerStore(name string, created time.Time, cfg *ConsumerConfig) (ConsumerStore, error) {\n\tif fs == nil {\n\t\treturn nil, fmt.Errorf(\"filestore is nil\")\n\t}\n\tif fs.isClosed() {\n\t\treturn nil, ErrStoreClosed\n\t}\n\tif cfg == nil || name == _EMPTY_ {\n\t\treturn nil, fmt.Errorf(\"bad consumer config\")\n\t}\n\n\t// We now allow overrides from a stream being a filestore type and forcing a consumer to be memory store.\n\tif cfg.MemoryStorage {\n\t\t// Create directly here.\n\t\to := &consumerMemStore{ms: fs, name: name, cfg: *cfg}\n\t\tif err := fs.AddConsumer(o); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn o, nil\n\t}\n","sourceCodeStart":13311,"sourceCodeEnd":13347,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L13311-L13347","documentation":"Guard in (*fileStore).ConsumerStore: creating a consumer store on a nil fileStore pointer returns this error immediately. It is a defensive programming check — normal users should never be able to call the method on a nil file store, so hitting it indicates an internal state bug in the server.","triggerScenarios":"ConsumerStore(name, created, cfg) invoked on a *fileStore that is nil, which only occurs due to internal logic errors or test harness misuse of the filestore API.","commonSituations":"Custom builds, embedded nats-server usage with misuse of internal APIs, or test code constructing streams that fail to initialize but are still used.","solutions":["Audit the code path that produced a nil *fileStore — stream creation should have failed earlier.","In embedded usage, ensure the file store was successfully created and not set to nil before creating consumers.","Check earlier logs for stream creation errors that were ignored.","Report to nats-server maintainers with a reproduction if it happens in stock operation."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// ensure the stream store is initialized before creating consumers\nif fsStore == nil {\n    return errors.New(\"file store not initialized; create the stream first\")\n}","typeGuard":"func fsReady(fs *server.FileStore) bool { return fs != nil }","tryCatchPattern":"if err != nil {\n    if err.Error() == \"filestore is nil\" {\n        log.Printf(\"internal init bug: stream store nil at consumer creation\")\n    }\n}","preventionTips":["Handle stream-creation errors before using the store","In embedded usage, assert non-nil store before consumer creation","Check startup logs for failed stream initialization"],"tags":["jetstream","filestore","nil-pointer","guard"],"backgroundTag":"nil-receiver-guard","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}