{"record":{"id":"04bc3bcab11c343e","repo":"nats-io/nats-server","slug":"name-required","errorCode":null,"errorMessage":"name required","messagePattern":"name required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":414,"sourceCode":"\t// Checksum size for hash for msg records.\n\trecordHashSize = 8\n\n\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 {","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L396-L432","documentation":"newFileStoreWithCreatedAndMode validates the StreamConfig before constructing a file-based message store and returns 'name required' when cfg.Name is the empty string. A file store cannot exist without a named stream, so the library fails fast during store creation (also used during recovery).","triggerScenarios":"Creating a file-backed stream via AddStream/JetStream API with StreamConfig{Name: \"\"}; calling newFileStoreWithCreated directly with a zero-value StreamConfig.","commonSituations":"Programmatic stream creation where the Name field was forgotten; JSON config payloads missing the 'name' key; templating that renders an empty stream name.","solutions":["Set StreamConfig.Name to a non-empty stream name before adding the stream","Include the 'name' field in the JetStream AddStream API payload","Validate config structs (name non-empty, Storage == FileStorage) before calling the file store constructor"],"exampleFix":"// before\ncfg := StreamConfig{Storage: FileStorage}\n// after\ncfg := StreamConfig{Name: \"ORDERS\", Storage: FileStorage}","handlingStrategy":"validation","validationCode":"func streamConfigValidForFileStore(cfg StreamConfig) error {\n    if cfg.Name == \"\" {\n        return errors.New(\"name required\")\n    }\n    if cfg.Storage != FileStorage {\n        return errors.New(\"fileStore requires file storage type in config\")\n    }\n    return nil\n}","typeGuard":"func hasName(cfg StreamConfig) bool { return cfg.Name != \"\" }","tryCatchPattern":"fs, err := newFileStoreWithCreated(fcfg, cfg, created, prf, oldprf)\nif err != nil {\n    if err.Error() == \"name required\" {\n        // fix StreamConfig.Name and retry\n    }\n    return err\n}","preventionTips":["Always set StreamConfig.Name before AddStream or store construction","Require the 'name' field in JetStream API payloads (server enforces this anyway)","Validate generated/templated configs for empty names before applying"],"tags":["jetstream","filestore","config-validation"],"backgroundTag":"missing-stream-name","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}