{"record":{"id":"c4b8fee6927b5b8d","repo":"ory/hydra","slug":"janitor-requires-at-least-one-of-tokens-reque","errorCode":null,"errorMessage":"Janitor requires at least one of --tokens, --requests or --grants to be set","messagePattern":"Janitor requires at least one of --tokens, --requests or --grants to be set","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cli/handler_janitor.go","lineNumber":61,"sourceCode":"\t}\n}\n\nfunc (*JanitorHandler) Args(cmd *cobra.Command, args []string) error {\n\tif len(args) == 0 &&\n\t\t!flagx.MustGetBool(cmd, ReadFromEnv) &&\n\t\tlen(flagx.MustGetStringSlice(cmd, Config)) == 0 {\n\n\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}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cli/handler_janitor.go#L43-L79","documentation":"Janitor deletes expired entities but only the categories you opt into. Args validates that at least one of --tokens, --requests, or --grants is set; otherwise it would run a no-op sweep, so it prints usage and returns this error.","triggerScenarios":"Running `hydra janitor <dsn>` without any of --tokens, --requests, --grants (or --only-tokens/--only-requests/--only-grants booleans) set.","commonSituations":"Copying an old janitor command that predates the flags; a scheduled job losing its flags after a manifest edit; assuming janitor clears everything by default.","solutions":["Add the desired scope flags: `hydra janitor <dsn> --tokens --requests --grants`.","If you only intend one category, pass just that flag, e.g. `--tokens`.","Update CronJob/deployment manifests to include the flags.","Check flags: newer versions accept --grants; older ones only --tokens/--requests — use flags your version supports."],"exampleFix":"// before\nhydra janitor $DSN\n\n// after\nhydra janitor $DSN --tokens --requests --grants","handlingStrategy":"validation","validationCode":"# Ensure at least one scope flag present:\ncase \"$*\" in\n  *--tokens*|*--requests*|*--grants*) ;;\n  *) echo \"janitor needs at least one of --tokens/--requests/--grants\" >&2; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Explicitly list cleanup scopes in every janitor invocation; never rely on defaults.","Keep the janitor command in one shared script/manifest.","Review janitor flags when upgrading Hydra versions.","Alert on janitor jobs exiting non-zero so missing flags are caught early."],"tags":["cli","janitor","arguments"],"backgroundTag":"missing-required-flag","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"}