Skip to content

Commit cf00305

Browse files
yasirusman85nroscinozyzyzyryxyPiotr Paulski
authored
fix(cli): improve error messages to guide AI agents and developers (#2161)
Co-authored-by: Nicholas Roscino <nroscino@google.com> Co-authored-by: Piotr Paulski <31672205+zyzyzyryxy@users.noreply.github.com> Co-authored-by: Piotr Paulski <piotrpaulski@chromium.org>
1 parent a38ef5e commit cf00305

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

src/bin/chrome-devtools.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ startCliOptions.isolated!.description =
6262
startCliOptions.categoryExtensions!.default = true;
6363

6464
const y = yargs(hideBin(process.argv))
65+
.locale('en') // Force English to ensure error string matching works in .fail, all custom messages we output are in English anyways
6566
.scriptName('chrome-devtools')
6667
.showHelpOnFail(true)
6768
.usage('chrome-devtools <command> [...args] --flags')
@@ -78,7 +79,43 @@ const y = yargs(hideBin(process.argv))
7879
.version(VERSION)
7980
.strict()
8081
.help(true)
81-
.wrap(120);
82+
.wrap(120)
83+
.fail((msg, err) => {
84+
if (msg) {
85+
console.error('Error:', msg);
86+
if (
87+
msg.includes('Not enough non-option arguments') ||
88+
msg.includes('Unknown argument') ||
89+
msg.includes('Unknown arguments')
90+
) {
91+
console.error('\n=========================================');
92+
console.error('💡 TIP FOR AI AGENT / DEVELOPER:');
93+
console.error('In the `chrome-devtools` CLI:');
94+
console.error(
95+
'1. Required parameters MUST be passed as positional arguments (without flags).',
96+
);
97+
console.error(
98+
' - INCORRECT: chrome-devtools evaluate_script --expression "() => document.title"',
99+
);
100+
console.error(
101+
' - CORRECT: chrome-devtools evaluate_script "() => document.title"',
102+
);
103+
console.error(
104+
'2. Optional parameters are passed as double-dash options/flags (e.g. --pageId 1).',
105+
);
106+
console.error(
107+
'3. Make sure to escape quotes properly for your shell environment.',
108+
);
109+
console.error(
110+
'Run `chrome-devtools <command> --help` to see exact positional and optional parameters.',
111+
);
112+
console.error('=========================================');
113+
}
114+
} else if (err) {
115+
console.error(err);
116+
}
117+
process.exit(1);
118+
});
82119

83120
y.command(
84121
'start',

0 commit comments

Comments
 (0)