{"record":{"id":"b2e8feed9c8f0d3d","repo":"ory/hydra","slug":"a-dsn-is-required-as-a-positional-argument-when-no","errorCode":null,"errorMessage":"A DSN is required as a positional argument when not passing any of the following flags:\n- Using the environment variable with flag -e, --read-from-env\n- Using the config file with flag -c, --config","messagePattern":"A DSN is required as a positional argument when not passing any of the following flags:\n- Using the environment variable with flag -e, --read-from-env\n- Using the config file with flag -c, --config","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cli/handler_janitor.go","lineNumber":53,"sourceCode":"\ntype JanitorHandler struct {\n\tdOpts []driver.OptionsModifier\n}\n\nfunc newJanitorHandler(dOpts []driver.OptionsModifier) *JanitorHandler {\n\treturn &JanitorHandler{\n\t\tdOpts: dOpts,\n\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}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cli/handler_janitor.go#L35-L71","documentation":"The `hydra janitor` CLI Args validation requires a DSN to be resolvable from a positional argument, the environment (-e/--read-from-env), or a config file (-c/--config). If none are present, it prints usage and returns this formatted CLI error instead of starting the janitor.","triggerScenarios":"Running `hydra janitor` (or janitor via SDK's Args) with no positional DSN and without -e or -c flags.","commonSituations":"Forgetting the DSN argument in a cron job / Kubernetes CronJob command; relying on env vars without passing -e; config file path typo so the flag was never given; upgrading hydra so the old positional argument was dropped from a script.","solutions":["Pass the DSN positionally: `hydra janitor postgres://user:pass@host/db`.","Or export DSN and run with `hydra janitor -e`.","Or provide a config file: `hydra janitor -c hydra.yml` containing the dsn property.","Fix CI/CD or CronJob manifests so the flag/argument is actually included."],"exampleFix":"// before\ncommand: [\"hydra\", \"janitor\", \"--requests\"]\n\n// after\ncommand: [\"hydra\", \"janitor\", \"--requests\", \"-e\"]  # with DSN env var set\n# or: [\"hydra\", \"janitor\", \"--requests\", \"postgres://...\"]","handlingStrategy":"validation","validationCode":"# Shell guard before invoking janitor:\nif [ -z \"$DSN\" ] && [ $# -lt 1 ]; then\n  echo \"Provide DSN positionally, or set DSN and pass -e, or pass -c config.yml\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":"// When embedding janitor Args via SDK:\nif err := handler.Args(cmd, args); err != nil {\n    fmt.Fprintln(os.Stderr, err)\n    os.Exit(1)\n}","preventionTips":["Always include -e (with DSN env set) or -c in janitor CronJob commands.","Lint deployment manifests for required janitor flags.","Dry-run the command manually after manifest changes.","Pin the DSN in a secret rather than an ad-hoc positional argument in scripts."],"tags":["cli","configuration","janitor","arguments"],"backgroundTag":"missing-dsn-argument","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"}