{"record":{"id":"7073ef92647a5606","repo":"ory/hydra","slug":"values-for-limit-and-batch-size-should-both-be","errorCode":null,"errorMessage":"Values for --limit and --batch-size should both be greater than 0","messagePattern":"Values for --limit and --batch-size should both be greater than 0","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cli/handler_janitor.go","lineNumber":69,"sourceCode":"\t\tfmt.Printf(\"%s\\n\", cmd.UsageString())\n\t\t//lint:ignore ST1005 formatted error string used in CLI output\n\t\treturn fmt.Errorf(\"%s\\n%s\\n%s\\n\",\n\t\t\t\"A DSN is required as a positional argument when not passing any of the following flags:\",\n\t\t\t\"- Using the environment variable with flag -e, --read-from-env\",\n\t\t\t\"- Using the config file with flag -c, --config\")\n\t}\n\n\tif !flagx.MustGetBool(cmd, OnlyTokens) && !flagx.MustGetBool(cmd, OnlyRequests) && !flagx.MustGetBool(cmd, OnlyGrants) {\n\t\t//lint:ignore ST1005 formatted error string used in CLI output\n\t\treturn fmt.Errorf(\"%s\\n%s\\n\", cmd.UsageString(),\n\t\t\t\"Janitor requires at least one of --tokens, --requests or --grants to be set\")\n\t}\n\n\tlimit := flagx.MustGetInt(cmd, Limit)\n\tbatchSize := flagx.MustGetInt(cmd, BatchSize)\n\tif limit <= 0 || batchSize <= 0 {\n\t\t//lint:ignore ST1005 formatted error string used in CLI output\n\t\treturn fmt.Errorf(\"%s\\n%s\\n\", cmd.UsageString(),\n\t\t\t\"Values for --limit and --batch-size should both be greater than 0\")\n\t}\n\tif batchSize > limit {\n\t\t//lint:ignore ST1005 formatted error string used in CLI output\n\t\treturn fmt.Errorf(\"%s\\n%s\\n\", cmd.UsageString(),\n\t\t\t\"Value for --batch-size must not be greater than value for --limit\")\n\t}\n\n\treturn nil\n}\n\nfunc (j *JanitorHandler) RunE(cmd *cobra.Command, args []string) error {\n\treturn purge(cmd, args, j.dOpts)\n}\n\nfunc purge(cmd *cobra.Command, args []string, dOpts []driver.OptionsModifier) error {\n\tctx := cmd.Context()\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cli/handler_janitor.go#L51-L87","documentation":"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.","triggerScenarios":"Running `hydra janitor ... --limit 0`, a negative value, or --batch-size 0 / negative.","commonSituations":"Setting --limit 0 intending 'unlimited'; templating numeric values from env vars that evaluate to empty/0; typo like --limit=-1 in a shell script.","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)."],"exampleFix":"// before\nhydra janitor $DSN --tokens --limit 0\n\n// after\nhydra janitor $DSN --tokens --limit 100 --batch-size 20","handlingStrategy":"validation","validationCode":"LIMIT=${JANITOR_LIMIT:-100}; BATCH=${JANITOR_BATCH:-20}\nif ! [ \"$LIMIT\" -gt 0 ] || ! [ \"$BATCH\" -gt 0 ]; then\n  echo \"--limit and --batch-size must be > 0\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","janitor","arguments","validation"],"backgroundTag":"invalid-flag-value","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}