{"id":"48155784e9d35da1","repo":"jestjs/jest","slug":"both-onlyfailures-and-watchall-were-specified","errorCode":null,"errorMessage":"Both --onlyFailures and --watchAll were specified, only one is allowed.","messagePattern":"Both --onlyFailures and --watchAll were specified, only one is allowed\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-cli/src/args.ts","lineNumber":38,"sourceCode":"  }\n\n  for (const key of [\n    'onlyChanged',\n    'lastCommit',\n    'changedFilesWithAncestor',\n    'changedSince',\n  ]) {\n    if (argv[key] && argv.watchAll) {\n      throw new Error(\n        `Both --${key} and --watchAll were specified, but cannot be used ` +\n          'together. Try the --watch option which reruns only tests ' +\n          'related to changed files.',\n      );\n    }\n  }\n\n  if (argv.onlyFailures && argv.watchAll) {\n    throw new Error(\n      'Both --onlyFailures and --watchAll were specified, only one is allowed.',\n    );\n  }\n\n  if (argv.findRelatedTests && argv._.length === 0) {\n    throw new Error(\n      'The --findRelatedTests option requires file paths to be specified.\\n' +\n        'Example usage: jest --findRelatedTests ./src/source.js ' +\n        './src/index.js.',\n    );\n  }\n\n  if (\n    Object.prototype.hasOwnProperty.call(argv, 'maxWorkers') &&\n    argv.maxWorkers === undefined\n  ) {\n    throw new Error(\n      'The --maxWorkers (-w) option requires a number or string to be specified.\\n' +","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-cli/src/args.ts#L20-L56","documentation":"A dedicated guard in `check` (packages/jest-cli/src/args.ts:37) forbids `--onlyFailures` together with `--watchAll`. `--onlyFailures` reads the previous run's results to select failed tests, while `--watchAll` triggers a full re-run on any change; the two selection strategies conflict and the failure cache is not maintained across watch reruns.","triggerScenarios":"`jest --onlyFailures --watchAll` or `jest -f --watchAll`.","commonSituations":"Wanting a watch loop that only re-runs failing tests; combining flags from different scripts.","solutions":["Use `--watch` with `--onlyFailures` if available in your workflow, or run `--onlyFailures` once without watch.","If you need continuous full re-runs, drop `--onlyFailures` and keep `--watchAll`."],"exampleFix":"# before\njest --onlyFailures --watchAll\n\n# after\njest --onlyFailures  # one-shot rerun of failures","handlingStrategy":"validation","validationCode":"function validate(argv: { onlyFailures?: boolean; watchAll?: boolean }): void {\n  if (argv.onlyFailures && argv.watchAll) {\n    throw new Error('--onlyFailures cannot be combined with --watchAll');\n  }\n}","typeGuard":"const onlyFailuresWithWatchAll = (a: any) => Boolean(a.onlyFailures && a.watchAll);","tryCatchPattern":null,"preventionTips":["Run --onlyFailures as a one-shot, not inside watchAll.","Keep failure-rerun scripts separate from watch scripts."],"tags":["jest-cli","cli-args","watch","onlyfailures"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}