{"record":{"id":"311c73704aa5e5ae","repo":"nats-io/nats-server","slug":"invalid-storage-type","errorCode":null,"errorMessage":"invalid storage type","messagePattern":"invalid storage type","errorType":"error_code","errorClass":"JSStreamInvalidConfigError","httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":1908,"sourceCode":"\n\tcfg := *config\n\n\tif _, err := cfg.Retention.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid retention\"))\n\t}\n\tif _, err := cfg.Discard.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid discard policy\"))\n\t}\n\tif _, err := cfg.Compression.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid compression\"))\n\t}\n\n\t// Make file the default.\n\tif cfg.Storage == 0 {\n\t\tcfg.Storage = FileStorage\n\t}\n\tif _, err := cfg.Storage.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid storage type\"))\n\t}\n\n\tif cfg.Replicas == 0 {\n\t\tcfg.Replicas = 1\n\t}\n\tif cfg.Replicas > StreamMaxReplicas {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"maximum replicas is %d\", StreamMaxReplicas))\n\t}\n\tif cfg.Replicas < 0 {\n\t\treturn cfg, NewJSReplicasCountCannotBeNegativeError()\n\t}\n\tif cfg.MaxMsgs == 0 || cfg.MaxMsgs < -1 {\n\t\tif pedantic && cfg.MaxMsgs < -1 {\n\t\t\treturn StreamConfig{}, NewJSPedanticError(fmt.Errorf(\"max_msgs must be set to -1\"))\n\t\t}\n\t\tcfg.MaxMsgs = -1\n\t}\n\tif cfg.MaxMsgsPer == 0 || cfg.MaxMsgsPer < -1 {","sourceCodeStart":1890,"sourceCodeEnd":1926,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1890-L1926","documentation":"cfg.Storage (StorageType enum: File or Memory) failed to marshal to JSON, meaning it is not a recognized storage type. This check runs after the default of FileStorage is applied only for the exact zero value, so any other out-of-range value reaches the marshal call and errors as 'invalid storage type'.","triggerScenarios":"Passing Storage: StorageType(7) or other invalid numeric value; a partially initialized StreamConfig with garbage in the storage field; raw JSON requests with \"storage\" as a string like \"file\" instead of the numeric enum.","commonSituations":"Reading storage from a YAML/JSON config file into the wrong type; version skew between client enum values and server expectations; copy-paste mistakes between MemoryStorage/FileStorage constants.","solutions":["Set Storage to jetstream.FileStorage or jetstream.MemoryStorage explicitly.","Omit Storage to get the server default (FileStorage).","Validate the numeric enum value before building the config.","If loading from a config file, map the string to the correct typed constant."],"exampleFix":"// before\nstorage := cfgYAML.Storage // string \"file\"\nsc := jetstream.StreamConfig{Name: \"ORDERS\", Storage: jetstream.StorageType(storage)}\n// after\nvar storage jetstream.StorageType = jetstream.FileStorage\nif cfgYAML.Storage == \"memory\" {\n  storage = jetstream.MemoryStorage\n}\nsc := jetstream.StreamConfig{Name: \"ORDERS\", Storage: storage}","handlingStrategy":"validation","validationCode":"func validStorage(s jetstream.StorageType) error {\n  switch s {\n  case jetstream.FileStorage, jetstream.MemoryStorage:\n    return nil\n  }\n  return fmt.Errorf(\"invalid storage type: %d\", int(s))\n}","typeGuard":"func isKnownStorage(s jetstream.StorageType) bool {\n  return s == jetstream.FileStorage || s == jetstream.MemoryStorage\n}","tryCatchPattern":null,"preventionTips":["Set Storage only from FileStorage/MemoryStorage constants.","Omit Storage to let the server default to FileStorage.","Map config-file strings to typed constants explicitly.","Validate storage early when StreamConfig is assembled from external data."],"tags":["jetstream","stream-config","storage-type","enum"],"backgroundTag":"invalid-storage-type","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}