{"record":{"id":"6397f87f41a2375a","repo":"dgraph-io/badger","slug":"error-compression-level-v-must-be-greater-than","errorCode":null,"errorMessage":"ERROR: compression level(%v) must be greater than zero","messagePattern":"ERROR: compression level\\((.+?)\\) must be greater than zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":235,"sourceCode":"\t// of performance reasons, 1KB would be a good option too, allowing\n\t// values smaller than 1KB to be collocated with the keys in the LSM tree.\n\treturn DefaultOptions(path).WithValueThreshold(maxValueThreshold /* 1 MB */)\n}\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 := \"\"","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/options.go#L217-L253","documentation":"badger.ParseCompressionFlag parses a badger.compression superflag string of the form \"type[,level]\" (e.g. \"zstd:3\"). This error is returned when the level component is parsed successfully but is <= 0, which is invalid because compression levels must be positive.","triggerScenarios":"Passing a superflag like badger.compression=zstd:0 or badger.compression=snappy:-1 into Options.FromSuperFlag / configuration (CLI flag, env, config file).","commonSituations":"Hand-edited config files; templates that substitute a zero default; tools generating flags programmatically with an uninitialized level variable.","solutions":["Set the level to a positive integer (e.g. zstd:1 or zstd:3)","Omit the level entirely (e.g. badger.compression=zstd) to use the library default","Use badger.compression=none to disable compression","Validate the flag string in config pipelines before applying it to badger"],"exampleFix":"// before\nbadger.compression=zstd:0\n// after\nbadger.compression=zstd:3","handlingStrategy":"validation","validationCode":"func validateCompressionFlag(v string) error {\n    parts := strings.Split(v, \":\")\n    if len(parts) > 2 { return fmt.Errorf(\"invalid badger.compression: %s\", v) }\n    if len(parts) == 2 {\n        lvl, err := strconv.Atoi(parts[1])\n        if err != nil || lvl <= 0 { return fmt.Errorf(\"compression level must be > 0: %s\", v) }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"opts, err := badger.DefaultOptions(dir).FromSuperFlag(cfg)\nif err != nil && strings.Contains(err.Error(), \"must be greater than zero\") {\n    return fmt.Errorf(\"fix badger.compression in config: %w\", err)\n}","preventionTips":["Validate superflag strings in CI/config startup before applying them","Default to omitting the level (zstd alone) unless tuning","Never substitute 0 as 'default level'; 0 is invalid here"],"tags":["badger","configuration","compression","superflag"],"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"}