dgraph-io/badger · error

ERROR: Invalid badger.compression argument

Error message

ERROR: Invalid badger.compression argument

What it means

When parsing the badger.compression superflag string, badger splits on ':' or '='; if the split yields more than two parts the argument is malformed and this error is returned. Only "type" or "type:level" forms are accepted.

Source

Thrown at options.go:238

}

// parseCompression returns badger.compressionType and compression level given compression string
// of format compression-type:compression-level
func parseCompression(cStr string) (options.CompressionType, int, error) {
	cStrSplit := strings.Split(cStr, ":")
	cType := cStrSplit[0]
	level := 3

	var err error
	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++ {

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Use exactly one of: badger.compression=none|snappy|zstd or badger.compression=zstd:<positive-level>
  2. Strip extra separators from the flag value before passing to Options.FromSuperFlag
  3. Log/echo the resolved flag string at startup to catch concatenation bugs early

Example fix

// before
badger.compression=zstd:3:fast
// after
badger.compression=zstd:3
Defensive patterns

Strategy: validation

Validate before calling

func validCompressionArg(v string) bool {
    parts := strings.Split(v, ":")
    return len(parts) <= 2 && parts[0] != ""
}

Try / catch

opts, err := badger.DefaultOptions(dir).FromSuperFlag(cfg)
if err != nil && strings.Contains(err.Error(), "Invalid badger.compression argument") {
    return fmt.Errorf("badger.compression must be 'type' or 'type:level', got %q", cfg)
}

Prevention

When it happens

Trigger: Passing strings like "zstd:3:fast" or "zstd=3=x" as badger.compression; typos inserting extra separators into the flag.

Common situations: Environment variable concatenation mistakes; config templating that appends defaults; copy-pasting flags from other libraries with different syntax (e.g. json or key=value lists).

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/8ec4c911307f24ed. Report an issue: GitHub.