dgraph-io/badger · error

ERROR: compression type (%s) invalid

Error message

ERROR: compression type (%s) invalid

What it means

After parsing an optional level, the compression type token must be one of "zstd", "snappy", or "none". This error is returned when the type token matches none of those, indicating an unsupported or misspelled compression name.

Source

Thrown at options.go:248

	if len(cStrSplit) == 2 {
		level, err = strconv.Atoi(cStrSplit[1])
		y.Check(err)
		if level <= 0 {
			return 0, 0,
				fmt.Errorf("ERROR: compression level(%v) must be greater than zero", level)
		}
	} else if len(cStrSplit) > 2 {
		return 0, 0, fmt.Errorf("ERROR: Invalid badger.compression argument")
	}
	switch cType {
	case "zstd":
		return options.ZSTD, level, nil
	case "snappy":
		return options.Snappy, 0, nil
	case "none":
		return options.None, 0, nil
	}
	return 0, 0, fmt.Errorf("ERROR: compression type (%s) invalid", cType)
}

// generateSuperFlag generates an identical SuperFlag string from the provided Options.
func generateSuperFlag(options Options) string {
	superflag := ""
	v := reflect.ValueOf(&options).Elem()
	optionsStruct := v.Type()
	for i := 0; i < v.NumField(); i++ {
		if field := v.Field(i); field.CanInterface() {
			name := strings.ToLower(optionsStruct.Field(i).Name)
			kind := v.Field(i).Kind()
			switch kind {
			case reflect.Bool:
				superflag += name + "="
				superflag += fmt.Sprintf("%v; ", field.Bool())
			case reflect.Int, reflect.Int64:
				superflag += name + "="
				superflag += fmt.Sprintf("%v; ", field.Int())

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Use one of the supported values exactly: none, snappy, or zstd
  2. Check for case/whitespace issues in the config source; normalize the value before parsing
  3. If another codec is required, check whether the installed badger version supports it or implement a custom path upstream

Example fix

// before
badger.compression=gzip
// after
badger.compression=zstd:1
Defensive patterns

Strategy: validation

Validate before calling

func knownCompressionType(v string) bool {
    t := strings.SplitN(v, ":", 2)[0]
    switch t {
    case "zstd", "snappy", "none":
        return true
    }
    return false
}

Try / catch

opts, err := badger.DefaultOptions(dir).FromSuperFlag(cfg)
if err != nil && strings.Contains(err.Error(), "compression type") {
    return fmt.Errorf("unsupported compression %q; use none|snappy|zstd", cfg)
}

Prevention

When it happens

Trigger: Passing badger.compression=gzip, badger.compression=ZSTD (case-sensitivity in the switch), or any misspelled/renamed type into Options.FromSuperFlag.

Common situations: Users assuming other codecs (gzip, lz4) are supported; config written for a different library; shell scripts uppercasing values.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/19a9d9444729cb2d. Report an issue: GitHub.