{"record":{"id":"6512c83ab1dfcff7","repo":"yarnpkg/yarn","slug":"toomanyarguments-6512c8","errorCode":null,"errorMessage":"tooManyArguments","messagePattern":"tooManyArguments","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/why.js","lineNumber":133,"sourceCode":"export function hasWrapper(commander: Object, args: Array<string>): boolean {\n  return true;\n}\n\n// to conform to the current standard '#' as package tree separator\nfunction toStandardPathString(pathString: string): string {\n  const str = pathString.replace(/\\//g, '#');\n  if (str[0] === '#') {\n    return str.slice(1);\n  }\n  return str;\n}\n\nexport async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {\n  if (!args.length) {\n    throw new MessageError(reporter.lang('missingWhyDependency'));\n  }\n  if (args.length > 1) {\n    throw new MessageError(reporter.lang('tooManyArguments', 1));\n  }\n\n  const query = await cleanQuery(config, args[0]);\n\n  reporter.step(1, 4, reporter.lang('whyStart', args[0]), emoji.get('thinking_face'));\n\n  // init\n  reporter.step(2, 4, reporter.lang('whyInitGraph'), emoji.get('truck'));\n  const lockfile = await Lockfile.fromDirectory(config.lockfileFolder, reporter);\n  const install = new Install(flags, config, reporter, lockfile);\n  const {requests: depRequests, patterns, workspaceLayout} = await install.fetchRequestFromCwd();\n  await install.resolver.init(depRequests, {\n    isFlat: install.flags.flat,\n    isFrozen: install.flags.frozenLockfile,\n    workspaceLayout,\n  });\n  const hoisted = await install.linker.getFlatHoistedTree(patterns);\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/why.js#L115-L151","documentation":"Thrown by 'yarn why' when more than one positional argument is given. The command accepts exactly one dependency query; extra arguments are rejected.","triggerScenarios":"Running 'yarn why foo bar' (two or more args), so args.length > 1.","commonSituations":"User expects to query multiple packages at once; trailing flags parsed as positional args due to ordering.","solutions":["Query one package at a time: 'yarn why foo', then 'yarn why bar'.","If you passed flags, put them before the query or ensure they are recognized as flags."],"exampleFix":"# before\n$ yarn why foo bar\n# after\n$ yarn why foo","handlingStrategy":"validation","validationCode":"if (args.length > 1) {\n  throw new Error(\"'yarn why' accepts exactly one argument; query packages one at a time.\");\n}","typeGuard":"function isSingleQuery(args: string[]): boolean {\n  return Array.isArray(args) && args.length === 1;\n}","tryCatchPattern":null,"preventionTips":["Pass flags before the query to avoid them being parsed as positional args.","Loop over packages in a wrapper script if you need to query several."],"tags":["cli-args","validation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}