{"record":{"id":"9f003a9e7469e2da","repo":"nats-io/nats-server","slug":"filestore-requires-file-storage-type-in-config","errorCode":null,"errorMessage":"fileStore requires file storage type in config","messagePattern":"fileStore requires file storage type in config","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":417,"sourceCode":"\t// Above this number of subjects, index.db may not be written regularly anymore, and\n\t// certain psim optimisations may not be used.\n\thighCardinalityThreshold = 1_000_000\n)\n\nfunc newFileStore(fcfg FileStoreConfig, cfg StreamConfig) (*fileStore, error) {\n\treturn newFileStoreWithCreated(fcfg, cfg, time.Now().UTC(), nil, nil)\n}\n\nfunc newFileStoreWithCreated(fcfg FileStoreConfig, cfg StreamConfig, created time.Time, prf, oldprf keyGen) (fs *fileStore, err error) {\n\treturn newFileStoreWithCreatedAndMode(fcfg, cfg, created, prf, oldprf, false)\n}\n\nfunc newFileStoreWithCreatedAndMode(fcfg FileStoreConfig, cfg StreamConfig, created time.Time, prf, oldprf keyGen, recovering bool) (fs *fileStore, err error) {\n\tif cfg.Name == _EMPTY_ {\n\t\treturn nil, fmt.Errorf(\"name required\")\n\t}\n\tif cfg.Storage != FileStorage {\n\t\treturn nil, fmt.Errorf(\"fileStore requires file storage type in config\")\n\t}\n\t// Default values.\n\tif fcfg.BlockSize == 0 {\n\t\tfcfg.BlockSize = dynBlkSize(cfg.Retention, cfg.MaxBytes, prf != nil)\n\t}\n\tif fcfg.BlockSize > maxBlockSize {\n\t\treturn nil, fmt.Errorf(\"filestore max block size is %s\", friendlyBytes(maxBlockSize))\n\t}\n\tif fcfg.CacheExpire == 0 {\n\t\tfcfg.CacheExpire = defaultCacheBufferExpiration\n\t}\n\tif fcfg.SubjectStateExpire == 0 {\n\t\tfcfg.SubjectStateExpire = defaultFssExpiration\n\t}\n\tif fcfg.SyncInterval == 0 {\n\t\tfcfg.SyncInterval = defaultSyncInterval\n\t}\n\tdios := fcfg.srv.diskIOSemaphore()","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L399-L435","documentation":"The JetStream file store constructor validates that the stream's storage type is FileStorage before creating a file-backed stream store. This error means a StreamConfig was passed with a different Storage value (e.g. MemoryStorage) while the fileStore implementation was selected. It is a config/implementation mismatch guard in newFileStoreWithCreatedAndMode (server/filestore.go:417).","triggerScenarios":"Calling file store creation (directly or via a stream restore/template) with StreamConfig.Storage set to MemoryStorage or any value other than FileStorage, while fileStore is the chosen implementation.","commonSituations":"Stream configs loaded from JSON where the storage field is missing or defaulted to memory; code that switches storage backends but reuses the file store constructor; restoring a snapshot into a memory-configured stream.","solutions":["Set Storage: FileStorage in the StreamConfig before creating the stream","If the stream should be memory-backed, use the memory store implementation instead of the file store","Validate the config with a pre-check before calling the API"],"exampleFix":"// before\ncfg := nats.StreamConfig{Name: \"ORDERS\", Storage: nats.MemoryStorage}\nfs, err := newFileStoreWithCreatedAndMode(fcfg, cfg, time.Now(), nil, nil, false)\n// after\ncfg := nats.StreamConfig{Name: \"ORDERS\", Storage: nats.FileStorage}\nfs, err := newFileStoreWithCreatedAndMode(fcfg, cfg, time.Now(), nil, nil, false)","handlingStrategy":"validation","validationCode":"func validFileStorage(cfg nats.StreamConfig) error {\n    if cfg.Storage != nats.FileStorage {\n        return fmt.Errorf(\"stream %q: got storage %v, want FileStorage\", cfg.Name, cfg.Storage)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set Storage explicitly in StreamConfig; never rely on zero values","Run config validation before store creation","Keep one config-building helper per storage backend"],"tags":["jetstream","storage-config","filestore","go"],"backgroundTag":"storage-type-mismatch","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}