{"record":{"id":"2d94cdd51b7dd875","repo":"GoogleChrome/lighthouse","slug":"please-provide-a-url","errorCode":null,"errorMessage":"Please provide a url","messagePattern":"Please provide a url","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/cli-flags.js","lineNumber":322,"sourceCode":"    .choices('form-factor', /** @type {const} */ (['mobile', 'desktop']))\n    .choices('throttling-method', /** @type {const} */ (['devtools', 'provided', 'simulate']))\n    .choices('preset', /** @type {const} */ (['perf', 'experimental', 'desktop']))\n\n    .check(argv => {\n      // Lighthouse doesn't need a URL if...\n      //   - We're just listing the available options.\n      //   - We're just printing the config.\n      //   - We're in auditMode (and we have artifacts already)\n      // If one of these don't apply, if no URL, stop the program and ask for one.\n      const isPrintSomethingMode = argv.listAllAudits || argv.listLocales || argv.listTraceCategories;\n      const isOnlyAuditMode = !!argv.auditMode && !argv.gatherMode;\n      if (isPrintSomethingMode || isOnlyAuditMode) {\n        return true;\n      } else if (argv._.length > 0) {\n        return true;\n      }\n\n      throw new Error('Please provide a url');\n    })\n    .epilogue('For more information on Lighthouse, see https://developers.google.com/web/tools/lighthouse/.')\n    .wrap(y.terminalWidth());\n}\n\n/**\n * @param {string=} manualArgv\n * @param {{noExitOnFailure?: boolean}=} options\n * @return {LH.CliFlags}\n */\nfunction getFlags(manualArgv, options = {}) {\n  let parser = getYargsParser(manualArgv);\n\n  if (options.noExitOnFailure) {\n    // Silence console.error() logging and don't process.exit().\n    // `parser.fail(false)` can be used in yargs once v17 is released.\n    parser = parser.fail((msg, err) => {\n      if (err) throw err;","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/GoogleChrome/lighthouse/blob/9515cd4e58ebed69f78742d932b501c2cab8ad8f/cli/cli-flags.js#L304-L340","documentation":"Lighthouse's yargs parser uses a .check() handler to enforce that a target URL is provided before any audit work begins. The check allows several bypass conditions — listing audits (--list-all-audits), listing locales (--list-locales), listing trace categories (--list-trace-categories), or processing saved artifacts (--audit-mode without --gather-mode). If none of those bypass conditions are met and no positional argument (the URL) is present, this error halts the program.","triggerScenarios":"Running the Lighthouse CLI with zero positional arguments and none of the bypass flags. Specifically: argv._.length === 0 (no positional URL), isPrintSomethingMode is false (no --list-all-audits/--list-locales/--list-trace-categories), and isOnlyAuditMode is false (no --audit-mode, or --audit-mode combined with --gather-mode).","commonSituations":"Forgetting the URL entirely; shell variable expansion producing an empty string (lighthouse \"$URL\" where URL is unset); quoting issues that consume the positional argument; migrating a script that previously read the URL from a different position.","solutions":["Add the target URL as the final positional argument: lighthouse https://example.com","If your shell variable may be empty, guard it: [ -n \"$TARGET_URL\" ] && lighthouse \"$TARGET_URL\"","If you intended to list audits or locales, add the appropriate flag: lighthouse --list-all-audits","If processing saved artifacts, ensure --audit-mode is set without --gather-mode: lighthouse --audit-mode=./artifacts"],"exampleFix":"# before\nlighthouse --output=json\n# after\nlighthouse https://example.com --output=json","handlingStrategy":"validation","validationCode":"// Validate URL is present before calling Lighthouse\nfunction validateArgs(args) {\n  const hasUrl = args.some(arg => arg.startsWith('http')) ||\n    (args.length > 0 && !args.every(a => a.startsWith('--')));\n  if (!hasUrl) {\n    console.error('Error: A URL is required. Usage: lighthouse <url> [options]');\n    process.exit(1);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the URL as the first positional argument in scripts","Guard shell scripts: if [ -z \"$1\" ]; then echo 'URL required'; exit 1; fi","When building yargs commands programmatically, add a demandCommand() call"],"tags":["cli","validation","usage"],"backgroundTag":null,"analyzedSha":"9515cd4e58ebed69f78742d932b501c2cab8ad8f","analyzedAt":"2026-08-13T06:28:10.346Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}