{"record":{"id":"8ec4c911307f24ed","repo":"dgraph-io/badger","slug":"error-invalid-badger-compression-argument","errorCode":null,"errorMessage":"ERROR: Invalid badger.compression argument","messagePattern":"ERROR: Invalid badger\\.compression argument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":238,"sourceCode":"}\n\n// parseCompression returns badger.compressionType and compression level given compression string\n// of format compression-type:compression-level\nfunc parseCompression(cStr string) (options.CompressionType, int, error) {\n\tcStrSplit := strings.Split(cStr, \":\")\n\tcType := cStrSplit[0]\n\tlevel := 3\n\n\tvar err error\n\tif len(cStrSplit) == 2 {\n\t\tlevel, err = strconv.Atoi(cStrSplit[1])\n\t\ty.Check(err)\n\t\tif level <= 0 {\n\t\t\treturn 0, 0,\n\t\t\t\tfmt.Errorf(\"ERROR: compression level(%v) must be greater than zero\", level)\n\t\t}\n\t} else if len(cStrSplit) > 2 {\n\t\treturn 0, 0, fmt.Errorf(\"ERROR: Invalid badger.compression argument\")\n\t}\n\tswitch cType {\n\tcase \"zstd\":\n\t\treturn options.ZSTD, level, nil\n\tcase \"snappy\":\n\t\treturn options.Snappy, 0, nil\n\tcase \"none\":\n\t\treturn options.None, 0, nil\n\t}\n\treturn 0, 0, fmt.Errorf(\"ERROR: compression type (%s) invalid\", cType)\n}\n\n// generateSuperFlag generates an identical SuperFlag string from the provided Options.\nfunc generateSuperFlag(options Options) string {\n\tsuperflag := \"\"\n\tv := reflect.ValueOf(&options).Elem()\n\toptionsStruct := v.Type()\n\tfor i := 0; i < v.NumField(); i++ {","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/options.go#L220-L256","documentation":"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.","triggerScenarios":"Passing strings like \"zstd:3:fast\" or \"zstd=3=x\" as badger.compression; typos inserting extra separators into the flag.","commonSituations":"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).","solutions":["Use exactly one of: badger.compression=none|snappy|zstd or badger.compression=zstd:<positive-level>","Strip extra separators from the flag value before passing to Options.FromSuperFlag","Log/echo the resolved flag string at startup to catch concatenation bugs early"],"exampleFix":"// before\nbadger.compression=zstd:3:fast\n// after\nbadger.compression=zstd:3","handlingStrategy":"validation","validationCode":"func validCompressionArg(v string) bool {\n    parts := strings.Split(v, \":\")\n    return len(parts) <= 2 && parts[0] != \"\"\n}","typeGuard":null,"tryCatchPattern":"opts, err := badger.DefaultOptions(dir).FromSuperFlag(cfg)\nif err != nil && strings.Contains(err.Error(), \"Invalid badger.compression argument\") {\n    return fmt.Errorf(\"badger.compression must be 'type' or 'type:level', got %q\", cfg)\n}","preventionTips":["Keep one separator max in the flag value; scrub env concatenation bugs","Echo the effective superflag at startup","Pin flags in config files rather than composing in shell scripts"],"tags":["badger","configuration","compression","superflag","parsing"],"backgroundTag":"invalid-config-value","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"}