{"record":{"id":"d43feef6de2854fa","repo":"nats-io/nats-server","slug":"unknown-compression-algorithm","errorCode":null,"errorMessage":"unknown compression algorithm","messagePattern":"unknown compression algorithm","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":138,"sourceCode":"\tswitch alg {\n\tcase NoCompression:\n\t\treturn \"None\"\n\tcase S2Compression:\n\t\treturn \"S2\"\n\tdefault:\n\t\treturn \"Unknown StoreCompression\"\n\t}\n}\n\nfunc (alg StoreCompression) MarshalJSON() ([]byte, error) {\n\tvar str string\n\tswitch alg {\n\tcase S2Compression:\n\t\tstr = \"s2\"\n\tcase NoCompression:\n\t\tstr = \"none\"\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unknown compression algorithm\")\n\t}\n\treturn json.Marshal(str)\n}\n\nfunc (alg *StoreCompression) UnmarshalJSON(b []byte) error {\n\tvar str string\n\tif err := json.Unmarshal(b, &str); err != nil {\n\t\treturn err\n\t}\n\tswitch str {\n\tcase \"s2\":\n\t\t*alg = S2Compression\n\tcase \"none\":\n\t\t*alg = NoCompression\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown compression algorithm\")\n\t}\n\treturn nil","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L120-L156","documentation":"StoreCompression.MarshalJSON returns this error when serializing a compression algorithm value that is neither S2Compression nor NoCompression. The library only supports these two named algorithms for file-store stream compression, so an unknown value has no JSON representation.","triggerScenarios":"Marshaling a FileStoreConfig/StreamConfig whose StoreCompression field was set to an undefined or out-of-range value (e.g. constructed with an invalid cast like StoreCompression(7)).","commonSituations":"Deserializing a server config from a newer/older nats-server version that defined additional compression algorithms; hand-assembling config structs with raw integer constants.","solutions":["Set compression to CompressionS2 (S2Compression) or CompressionNone (NoCompression) only","Re-decode the config with a matching server version to populate valid enum values","Fix any integer casts that construct StoreCompression from raw numbers"],"exampleFix":"// before\nalg := StoreCompression(7)\n// after\nalg := CompressionS2","handlingStrategy":"validation","validationCode":"func validCompression(alg StoreCompression) bool {\n    return alg == CompressionS2 || alg == CompressionNone\n}","typeGuard":"func isKnownCompression(alg StoreCompression) bool {\n    return alg == S2Compression || alg == NoCompression\n}","tryCatchPattern":"b, err := json.Marshal(cfg)\nif err != nil {\n    if err.Error() == \"unknown compression algorithm\" {\n        cfg.Compression = CompressionNone\n        b, err = json.Marshal(cfg)\n    }\n    return err\n}","preventionTips":["Only assign named constants (CompressionS2/CompressionNone), never raw ints","Keep server and client config-generation code on the same version","Round-trip marshal/unmarshal configs in tests"],"tags":["jetstream","filestore","serialization"],"backgroundTag":"unknown-compression-algorithm","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}