ory/hydra · error

Values for --limit and --batch-size should both be greater t

Error message

Values for --limit and --batch-size should both be greater than 0

What it means

Args validates janitor paging knobs: --limit (max rows deleted per run) and --batch-size (rows per batch) must both be strictly greater than 0, otherwise batching math would loop forever or fail. It returns this formatted CLI error with usage when either is <= 0.

Source

Thrown at cmd/cli/handler_janitor.go:69

		fmt.Printf("%s\n", cmd.UsageString())
		//lint:ignore ST1005 formatted error string used in CLI output
		return fmt.Errorf("%s\n%s\n%s\n",
			"A DSN is required as a positional argument when not passing any of the following flags:",
			"- Using the environment variable with flag -e, --read-from-env",
			"- Using the config file with flag -c, --config")
	}

	if !flagx.MustGetBool(cmd, OnlyTokens) && !flagx.MustGetBool(cmd, OnlyRequests) && !flagx.MustGetBool(cmd, OnlyGrants) {
		//lint:ignore ST1005 formatted error string used in CLI output
		return fmt.Errorf("%s\n%s\n", cmd.UsageString(),
			"Janitor requires at least one of --tokens, --requests or --grants to be set")
	}

	limit := flagx.MustGetInt(cmd, Limit)
	batchSize := flagx.MustGetInt(cmd, BatchSize)
	if limit <= 0 || batchSize <= 0 {
		//lint:ignore ST1005 formatted error string used in CLI output
		return fmt.Errorf("%s\n%s\n", cmd.UsageString(),
			"Values for --limit and --batch-size should both be greater than 0")
	}
	if batchSize > limit {
		//lint:ignore ST1005 formatted error string used in CLI output
		return fmt.Errorf("%s\n%s\n", cmd.UsageString(),
			"Value for --batch-size must not be greater than value for --limit")
	}

	return nil
}

func (j *JanitorHandler) RunE(cmd *cobra.Command, args []string) error {
	return purge(cmd, args, j.dOpts)
}

func purge(cmd *cobra.Command, args []string, dOpts []driver.OptionsModifier) error {
	ctx := cmd.Context()

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Pass positive integers for both flags, e.g. --limit 100 --batch-size 20.
  2. If you meant unlimited, omit the flags (defaults apply) or use a large positive limit.
  3. Fix env/templated values so they resolve to positive numbers.
  4. Ensure batch-size <= limit (see the related batch-size error).

Example fix

// before
hydra janitor $DSN --tokens --limit 0

// after
hydra janitor $DSN --tokens --limit 100 --batch-size 20
Defensive patterns

Strategy: validation

Validate before calling

LIMIT=${JANITOR_LIMIT:-100}; BATCH=${JANITOR_BATCH:-20}
if ! [ "$LIMIT" -gt 0 ] || ! [ "$BATCH" -gt 0 ]; then
  echo "--limit and --batch-size must be > 0" >&2; exit 1
fi

Prevention

When it happens

Trigger: Running `hydra janitor ... --limit 0`, a negative value, or --batch-size 0 / negative.

Common situations: Setting --limit 0 intending 'unlimited'; templating numeric values from env vars that evaluate to empty/0; typo like --limit=-1 in a shell script.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/7073ef92647a5606. Report an issue: GitHub.