{"record":{"id":"ed7842be1b5bbba5","repo":"thanos-io/thanos","slug":"compaction-min-must-be-less-than-or-equal-to-compa","errorCode":null,"errorMessage":"compaction-min must be less than or equal to compaction-max","messagePattern":"compaction-min must be less than or equal to compaction-max","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":780,"sourceCode":"\tmaxTime := model.TimeOrDuration(cmd.Flag(\"max-time\", \"End of time range limit to replicate. Thanos Replicate will replicate only metrics, which happened earlier than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y.\").\n\t\tDefault(\"9999-12-31T23:59:59Z\"))\n\tids := cmd.Flag(\"id\", \"Block to be replicated to the destination bucket. IDs will be used to match blocks and other matchers will be ignored. When specified, this command will be run only once after successful replication. Repeated field\").Strings()\n\tignoreMarkedForDeletion := cmd.Flag(\"ignore-marked-for-deletion\", \"Do not replicate blocks that have deletion mark.\").Bool()\n\n\tcmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error {\n\t\tmatchers, err := replicate.ParseFlagMatchers(tbc.matcherStrs)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"parse block label matchers\")\n\t\t}\n\n\t\tvar resolutionLevels []compact.ResolutionLevel\n\t\tfor _, lvl := range tbc.resolutions {\n\t\t\tresolutionLevels = append(resolutionLevels, compact.ResolutionLevel(lvl.Milliseconds()))\n\t\t}\n\n\t\tif len(tbc.compactions) == 0 {\n\t\t\tif tbc.compactMin > tbc.compactMax {\n\t\t\t\treturn errors.New(\"compaction-min must be less than or equal to compaction-max\")\n\t\t\t}\n\t\t\ttbc.compactions = []int{}\n\t\t\tfor compactionLevel := tbc.compactMin; compactionLevel <= tbc.compactMax; compactionLevel++ {\n\t\t\t\ttbc.compactions = append(tbc.compactions, compactionLevel)\n\t\t\t}\n\t\t}\n\n\t\tblockIDs := make([]ulid.ULID, 0, len(*ids))\n\t\tfor _, id := range *ids {\n\t\t\tbid, err := ulid.Parse(id)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"invalid ULID found in --id flag\")\n\t\t\t}\n\t\t\tblockIDs = append(blockIDs, bid)\n\t\t}\n\n\t\treturn replicate.RunReplicate(\n\t\t\tg,","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L762-L798","documentation":"The replicate command derives compaction levels from --compaction-min and --compaction-max (when --compactions is not given). It explicitly rejects a configuration where min exceeds max with this error, because the generated level range would be empty/inverted.","triggerScenarios":"Running `thanos tools bucket replicate` with --compaction-min greater than --compaction-max (e.g. min=3 max=1) and no explicit --compactions list — cmd/thanos/tools_bucket.go:780.","commonSituations":"Users swapping the two flags on the command line or scripting where the values are computed in the wrong order; also confusion between compaction levels (0,1,2) and time ranges.","solutions":["Swap the values so compaction-min <= compaction-max (valid levels: 0, 1, 2).","Alternatively pass an explicit --compactions list (e.g. --compactions=0,1) and the min/max check is skipped.","Review automation scripts that compute min/max and enforce ordering before invoking the command."],"exampleFix":"// before\nthanos tools bucket replicate ... --compaction-min=2 --compaction-max=1\n// after\nthanos tools bucket replicate ... --compaction-min=1 --compaction-max=2","handlingStrategy":"validation","validationCode":"if compactionMin > compactionMax {\n    return errors.New(\"--compaction-min must be <= --compaction-max (valid levels: 0,1,2)\")\n}","typeGuard":null,"tryCatchPattern":"if err := replicateCmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"compaction-min must be less than or equal\") {\n        os.Exit(2) // fix flag ordering and retry\n    }\n}","preventionTips":["Remember valid compaction levels are 0, 1, 2","Pass an explicit --compactions list to bypass min/max entirely","In scripts, sort min/max before composing the command line","Double-check flag order when hand-typing long commands"],"tags":["cli","flags","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}