{"record":{"id":"3aea21ce42f29707","repo":"microsoft/playwright","slug":"command-is-required","errorCode":null,"errorMessage":"Command is required","messagePattern":"Command is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/cli-daemon/daemon.ts","lineNumber":147,"sourceCode":"\nasync function deleteSessionFile(clientInfo: ClientInfo, sessionConfig: SessionConfig) {\n  await fs.promises.unlink(sessionConfig.socketPath).catch(() => {});\n  if (!sessionConfig.cli.persistent) {\n    const sessionFile = path.join(clientInfo.daemonProfilesDir, `${sessionConfig.name}.session`);\n    await fs.promises.rm(sessionFile).catch(() => {});\n  }\n}\n\nfunction formatResult(result: CallToolResult) {\n  const isError = result.isError;\n  const text = result.content[0].type === 'text' ? result.content[0].text : undefined;\n  return { isError, text };\n}\n\nfunction parseCliCommand(args: Record<string, string> & { _: string[] }): { toolName: string, toolParams: NonNullable<CallToolRequest['params']['arguments']> } {\n  const command = commands[args._[0]];\n  if (!command)\n    throw new Error('Command is required');\n  return parseCommand(command, args);\n}\n\nfunction daemonSocketPath(clientInfo: ClientInfo, sessionName: string): string {\n  return makeSocketPath('cli', `${clientInfo.workspaceDirHash}-${sessionName}`);\n}\n\nfunction createSessionConfig(clientInfo: ClientInfo, sessionName: string, browserInfo: BrowserInfo, options: {\n  ownership?: 'attached' | 'own',\n  persistent?: boolean,\n  exitOnStop?: boolean,\n} = {}): SessionConfig {\n  return {\n    name: sessionName,\n    version: clientInfo.version,\n    timestamp: Date.now(),\n    socketPath: daemonSocketPath(clientInfo, sessionName),\n    workspaceDir: clientInfo.workspaceDir,","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/cli-daemon/daemon.ts#L129-L165","documentation":"Thrown by `parseCliCommand` when `commands[args._[0]]` is falsy, i.e. the first positional argument does not match any registered CLI command name. This covers both an empty argument list and an unrecognized command name.","triggerScenarios":"Invoking the daemon `run` method with `params.args._` being empty, or with a first element that is not a registered command (e.g. a typo, an internal-only name, or a command removed in this version).","commonSituations":"Client sends a bare `run` with no command (e.g. just flags); user types a command name that doesn't exist (`'sreenshot'`); version mismatch where a command was renamed; a wrapper script that strips the command token before forwarding.","solutions":["Ensure `params.args._[0]` is a valid command name (e.g. `click`, `fill`, `screenshot`, `drop`).","If unsure of available commands, list them from the commands registry / `--help` output.","Check that argument parsing in the client preserves positional args in `_` (yargs-style) rather than dropping them."],"exampleFix":"// before\n{ args: { _: [], target: 'ref' } }\n// after\n{ args: { _: ['click'], target: 'ref' } }","handlingStrategy":"validation","validationCode":"// Ensure a command name is present and recognized before sending.\nconst KNOWN_COMMANDS = new Set(['click', 'fill', 'hover', 'screenshot', 'drop', /* ... */]);\nfunction buildRunArgs(positional: string[]) {\n  if (!positional.length || !KNOWN_COMMANDS.has(positional[0]))\n    throw new TypeError(`Unknown or missing command: ${positional[0] ?? '(none)'}`);\n  return { _: positional };\n}","typeGuard":"function hasCommand(args: { _: string[] }): args is { _: [string, ...string[]] } {\n  return args._.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always include a command name as the first positional argument.","Validate against the command registry before dispatching.","Keep client/daemon versions aligned so command sets match."],"tags":["cli","daemon","input-validation","command-parsing"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}