{"id":"95c2146b0500ff7d","repo":"tj/commander.js","slug":"option-creation-failed-due-to-no-flags-found-in","errorCode":null,"errorMessage":"option creation failed due to no flags found in '${flags}'.","messagePattern":"option creation failed due to no flags found in '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/option.js","lineNumber":372,"sourceCode":"    if (/^-[^-][^-]/.test(unsupportedFlag))\n      throw new Error(\n        `${baseError}\n- a short flag is a single dash and a single character\n  - either use a single dash and a single character (for a short flag)\n  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`,\n      );\n    if (shortFlagExp.test(unsupportedFlag))\n      throw new Error(`${baseError}\n- too many short flags`);\n    if (longFlagExp.test(unsupportedFlag))\n      throw new Error(`${baseError}\n- too many long flags`);\n\n    throw new Error(`${baseError}\n- unrecognised flag format`);\n  }\n  if (shortFlag === undefined && longFlag === undefined)\n    throw new Error(\n      `option creation failed due to no flags found in '${flags}'.`,\n    );\n\n  return { shortFlag, longFlag };\n}\n","sourceCodeStart":354,"sourceCodeEnd":378,"githubUrl":"https://github.com/tj/commander.js/blob/ba6d13ddb4243e5913367734f8c159089ffe7834/lib/option.js#L354-L378","documentation":"Thrown by splitOptionFlags() when, after processing every token, neither a short flag nor a long flag was found (both are undefined). This means the flags string contained no dash-prefixed token at all, e.g. an empty string, a bare placeholder like '<value>', or free text. Every Option must declare at least one flag, so this is rejected at construction.","triggerScenarios":"Constructing new Option(''), new Option('<value>'), new Option('description only'), or new Option(undefined) coerced to the string 'undefined' (which has no leading dash). Also when a variable meant to hold the flag name is empty.","commonSituations":"Passing only the value placeholder and forgetting the flag; passing the description as the first arg and the flag nowhere; empty config values feeding the flags string; refactors that moved the flag into a different argument.","solutions":["Include at least one flag token: new Option('-v <value>') or new Option('--name <value>').","Double-check argument order: the signature is new Option(flags, description).","If flags come from config, fail fast on empty/missing values before constructing the Option."],"exampleFix":"// before\nnew Option('<value>');\n\n// after\nnew Option('-v <value>');","handlingStrategy":"validation","validationCode":"// An Option must declare at least one flag token.\nfunction hasAnyFlag(flags) {\n  return String(flags).split(/[ |,]+/).some((t) => /^-[^-]/.test(t) || /^--[^-]/.test(t));\n}\nfunction assertHasFlag(flags) {\n  if (!hasAnyFlag(flags)) {\n    throw new Error(`Option flags must include at least one flag (got '${flags}')`);\n  }\n}\n// usage: assertHasFlag(flags); new Option(flags, description);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The Option constructor signature is new Option(flags, description); always pass a real flag first.","Reject empty/undefined flag values from config before constructing an Option.","Include at least '-x' or '--name'; a bare placeholder like '<value>' is not a flag."],"tags":["option","flags","validation","commander"],"analyzedSha":"ba6d13ddb4243e5913367734f8c159089ffe7834","analyzedAt":"2026-08-03T20:26:04.326Z","schemaVersion":2}