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
- Pass positive integers for both flags, e.g. --limit 100 --batch-size 20.
- If you meant unlimited, omit the flags (defaults apply) or use a large positive limit.
- Fix env/templated values so they resolve to positive numbers.
- 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
- Treat 0/negative as invalid when templating numeric flags from env.
- Quote and default env-sourced values: ${JANITOR_LIMIT:-100}.
- Add a manifest lint/test that runs janitor with --help and validates values.
- Document that omitting flags uses safe defaults; avoid explicit 0.
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
- Value for --batch-size must not be greater than value for --
- A DSN is required as a positional argument when not passing
- Janitor requires at least one of --tokens, --requests or --g
- When using flag -e, environment variable DSN must be set. Wh
- Could not create driver
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/7073ef92647a5606.
Report an issue: GitHub.