{"record":{"id":"935cc1b79a0305af","repo":"dgraph-io/badger","slug":"unsupported-compression-type","errorCode":null,"errorMessage":"Unsupported compression type","messagePattern":"Unsupported compression type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table/builder.go","lineNumber":523,"sourceCode":"func (b *Builder) shouldEncrypt() bool {\n\treturn b.opts.DataKey != nil\n}\n\n// compressData compresses the given data.\nfunc (b *Builder) compressData(data []byte) ([]byte, error) {\n\tswitch b.opts.Compression {\n\tcase options.None:\n\t\treturn data, nil\n\tcase options.Snappy:\n\t\tsz := s2.MaxEncodedLen(len(data))\n\t\tdst := b.alloc.Allocate(sz)\n\t\treturn s2.EncodeSnappy(dst, data), nil\n\tcase options.ZSTD:\n\t\tsz := y.ZSTDCompressBound(len(data))\n\t\tdst := b.alloc.Allocate(sz)\n\t\treturn y.ZSTDCompress(dst, data, b.opts.ZSTDCompressionLevel)\n\t}\n\treturn nil, errors.New(\"Unsupported compression type\")\n}\n\nfunc (b *Builder) buildIndex(bloom []byte) ([]byte, uint32) {\n\tbuilder := fbs.NewBuilder(3 << 20)\n\n\tboList, dataSize := b.writeBlockOffsets(builder)\n\t// Write block offset vector the the idxBuilder.\n\tfb.TableIndexStartOffsetsVector(builder, len(boList))\n\n\t// Write individual block offsets in reverse order to work around how Flatbuffers expects it.\n\tfor i := len(boList) - 1; i >= 0; i-- {\n\t\tbuilder.PrependUOffsetT(boList[i])\n\t}\n\tboEnd := builder.EndVector(len(boList))\n\n\tvar bfoff fbs.UOffsetT\n\t// Write the bloom filter.\n\tif len(bloom) > 0 {","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/table/builder.go#L505-L541","documentation":"Builder.compressData encodes a block according to the table's compression option. Only None (no compression), Snappy (s2), and ZSTD are implemented; any other options.Compression value causes compressData to return the 'Unsupported compression type' error, which fails the table build.","triggerScenarios":"Creating a table (via builder handleBlock) with opts.Compression set to a value other than options.None, options.Snappy, or options.ZSTD — e.g. a value from a different/older options enum, a custom integer cast, or an options file that persisted an unknown compression id.","commonSituations":"Migrating options across Badger versions where the compression enum changed; constructing Options programmatically with an invalid compression constant; restoring a DB whose option metadata references an algorithm this build doesn't support (e.g. a build without ZSTD support in older versions).","solutions":["Set Options.Compression to options.None, options.Snappy, or options.ZSTD before opening/creating the DB","If options were persisted, delete or fix the option/manifest so a supported compression id is loaded","Check the options package of your Badger version for the exact enum constants; don't cast raw ints into options.Compression","If high compression isn't required, fall back to options.None to guarantee compatibility"],"exampleFix":"// before\nopts := badger.DefaultOptions(dir)\nopts.Compression = options.Compression(7) // unknown type\n// after\nopts := badger.DefaultOptions(dir)\nopts.Compression = options.ZSTD // or options.Snappy / options.None","handlingStrategy":"validation","validationCode":"func compressionSupported(c options.Compression) bool {\n\treturn c == options.None || c == options.Snappy || c == options.ZSTD\n}\nif !compressionSupported(opts.Compression) {\n\treturn errors.New(\"unsupported compression type in options\")\n}","typeGuard":"func isKnownCompression(c options.Compression) bool {\n\tswitch c {\n\tcase options.None, options.Snappy, options.ZSTD:\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}\n}","tryCatchPattern":"data, err := b.compressData(dst, block, blockOff)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Unsupported compression type\") {\n\t\t// fall back to a supported compression\n\t\treturn b.compressData(dst, block, blockOff) // after correcting opts.Compression\n\t}\n\treturn err\n}","preventionTips":["Only assign options.Compression from its enum constants, never raw ints","Keep badger versions consistent between the process that writes options and the one that reads them","Default to options.Snappy or options.ZSTD from DefaultOptions rather than custom values","Check the options enum in your vendored version before enabling compression"],"tags":["compression","options","table-builder"],"backgroundTag":"unsupported-compression-type","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}