{"record":{"id":"8cb807206ff35b00","repo":"nats-io/nats-server","slug":"compression-algorithm-not-known","errorCode":null,"errorMessage":"compression algorithm not known","messagePattern":"compression algorithm not known","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":14512,"sourceCode":"\t\treturn 0, fmt.Errorf(\"metadata incomplete\")\n\t}\n\treturn 4 + n, nil\n}\n\nfunc (alg StoreCompression) Compress(buf []byte) ([]byte, error) {\n\tif len(buf) < checksumSize {\n\t\treturn nil, fmt.Errorf(\"uncompressed buffer is too short\")\n\t}\n\tbodyLen := int64(len(buf) - checksumSize)\n\tvar output bytes.Buffer\n\tvar writer io.WriteCloser\n\tswitch alg {\n\tcase NoCompression:\n\t\treturn buf, nil\n\tcase S2Compression:\n\t\twriter = s2.NewWriter(&output)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"compression algorithm not known\")\n\t}\n\n\tinput := bytes.NewReader(buf[:bodyLen])\n\tchecksum := buf[bodyLen:]\n\n\t// Compress the block content, but don't compress the checksum.\n\t// We will preserve it at the end of the block as-is.\n\tif n, err := io.CopyN(writer, input, bodyLen); err != nil {\n\t\treturn nil, fmt.Errorf(\"error writing to compression writer: %w\", err)\n\t} else if n != bodyLen {\n\t\treturn nil, fmt.Errorf(\"short write on body (%d != %d)\", n, bodyLen)\n\t}\n\tif err := writer.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"error closing compression writer: %w\", err)\n\t}\n\n\t// Now add the checksum back onto the end of the block.\n\tif n, err := output.Write(checksum); err != nil {","sourceCodeStart":14494,"sourceCodeEnd":14530,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L14494-L14530","documentation":"StoreCompression only supports NoCompression and S2Compression. Compress() hits its default case when the algorithm value is neither — meaning an unrecognized StoreCompression enum value was used, usually from an invalid byte in stored metadata or a binary built without a newer algorithm. From server/filestore.go.","triggerScenarios":"Decoding a block whose algorithm byte is outside the known enum, or code passing an uninitialized/invalid StoreCompression value into Compress().","commonSituations":"Store directories written by a newer nats-server with an algorithm this build doesn't know; corrupted metadata byte 3 of the compression header; application code constructing StoreCompression from a raw int.","solutions":["Confirm the algorithm byte value and that it matches a supported enum (NoCompression, S2Compression)","Upgrade nats-server to a build that knows the stored compression algorithm","Fix the corrupted/invalid algorithm byte by re-creating the affected block or consumer","Validate enum values in code that builds StoreCompression from config or bytes"],"exampleFix":"// before\nalg := StoreCompression(raw[3]) // 7 — unknown\nalg.Compress(block) // compression algorithm not known\n// after\nswitch StoreCompression(raw[3]) {\ncase NoCompression, S2Compression:\n\talg.Compress(block)\ndefault:\n\t// rebuild or upgrade server\n}","handlingStrategy":"type-guard","validationCode":"func knownAlgorithm(a StoreCompression) bool {\n\tswitch a {\n\tcase NoCompression, S2Compression:\n\t\treturn true\n\t}\n\treturn false\n}\nif !knownAlgorithm(alg) { return fmt.Errorf(\"unsupported compression %d\", alg) }","typeGuard":"func asKnownAlg(v byte) (StoreCompression, bool) {\n\ta := StoreCompression(v)\n\treturn a, a == NoCompression || a == S2Compression\n}","tryCatchPattern":"out, err := alg.Compress(block)\nif err != nil && strings.Contains(err.Error(), \"algorithm not known\") {\n\t// upgrade server or rebuild block with supported algorithm\n\treturn errUnsupportedAlg\n}","preventionTips":["Don't build StoreCompression from raw ints without validation","Match server version to whatever wrote the store directory","Whitelist compression algorithms in config parsing","Log the raw algorithm byte when it fails"],"tags":["jetstream","filestore","compression","compatibility"],"backgroundTag":"unknown-compression-algorithm","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}