{"record":{"id":"7c5a3196ca26bef9","repo":"jackwener/OpenCLI","slug":"subreddit-name-is-required","errorCode":null,"errorMessage":"Subreddit name is required.","messagePattern":"Subreddit name is required\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/reddit/subreddit-info.js","lineNumber":11,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\n\n// Reddit subreddit names: 3–21 chars, letters/digits/underscore, must start\n// with a letter. Accept an optional `r/` prefix and normalise it off.\nconst SUBREDDIT_NAME_RE = /^[A-Za-z][A-Za-z0-9_]{2,20}$/;\n\nexport function parseSubredditName(raw) {\n    let name = String(raw || '').trim();\n    if (!name) {\n        throw new ArgumentError(\n            'Subreddit name is required.',\n            'Pass a subreddit name like `python` (or `r/python`).',\n        );\n    }\n    if (name.startsWith('/r/')) name = name.slice(3);\n    else if (name.startsWith('r/')) name = name.slice(2);\n    if (!SUBREDDIT_NAME_RE.test(name)) {\n        throw new ArgumentError(\n            'Invalid subreddit name.',\n            'Subreddit names are 3–21 characters, start with a letter, and contain only letters, digits, and underscores.',\n        );\n    }\n    return name;\n}\n\ncli({\n    site: 'reddit',\n    name: 'subreddit-info',","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/subreddit-info.js#L1-L29","documentation":"`parseSubredditName` in the subreddit-info command throws this ArgumentError when the raw input is empty after trimming (String(raw || '').trim() is falsy). The library requires an explicit subreddit name and offers a hint ('Pass a subreddit name like `python` (or `r/python`)'). It is an input-validation error, not a network error.","triggerScenarios":"Calling the `sub` / subreddit-info command with no positional argument, an empty string, whitespace-only input, or undefined/null where a subreddit name was expected.","commonSituations":"Shell variable that failed to expand (e.g. \"$SUB\" unset); a script piping an empty value; forgetting the positional argument on the CLI.","solutions":["Pass a subreddit name as the positional argument, e.g. `sub python` or `sub r/python`","Check the shell/script variable feeding the command is actually set and non-empty","Trim user input before passing it; reject empty values in your own wrapper first","Catch ArgumentError and print the usage hint to the user"],"exampleFix":"// before\nawait runCli(['reddit', 'sub', subFromEnv]); // SUB unset -> throws\n// after\nif (!subFromEnv?.trim()) throw new Error('Set SUB env var, e.g. SUB=python');\nawait runCli(['reddit', 'sub', subFromEnv.trim()]);","handlingStrategy":"validation","validationCode":"// Validate the argument before calling the command:\nfunction requireSubreddit(raw) {\n  const name = String(raw ?? '').trim();\n  if (!name) throw new Error('Subreddit name is required — e.g. `python` or `r/python`');\n  return name;\n}","typeGuard":"function isNonEmptySubredditArg(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runCli(['reddit', 'sub', raw]);\n} catch (e) {\n  if (e instanceof ArgumentError && /required/i.test(e.message)) {\n    console.error('Usage: sub <name>  (e.g. sub python or sub r/python)');\n  } else throw e;\n}","preventionTips":["Check that shell variables feeding the argument are set ($SUB unset expands to empty)","Trim user input before passing it","Require the positional argument in your own wrapper with a friendly usage message"],"tags":["argument-validation","reddit","cli-input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}