Skip to content

Commit 3a3de6b

Browse files
Improve the logic when a task is not found (#5377)
1 parent faa9d72 commit 3a3de6b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

v-next/hardhat/src/internal/cli/main.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@ function getTaskFromCliArguments(
295295
}
296296

297297
if (task === undefined) {
298-
task = hre.tasks.getTask(arg);
299-
if (task === undefined) {
300-
return [arg];
298+
try {
299+
task = hre.tasks.getTask(arg);
300+
} catch (error) {
301+
return [arg]; // No task found
301302
}
302303
} else {
303304
const subtask = task.subtasks.get(arg);

v-next/hardhat/test/internal/cli/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ describe("main", function () {
431431
});
432432
});
433433

434+
it("should return the task id if not found", function () {
435+
const command = "npx hardhat undefined-task";
436+
437+
const cliArguments = command.split(" ").slice(2);
438+
const usedCliArguments = [false];
439+
440+
const res = parseTaskAndArguments(cliArguments, usedCliArguments, hre);
441+
442+
assert.deepEqual(res, ["undefined-task"]);
443+
});
444+
434445
it("should throw because the parameter is not defined", function () {
435446
const command = "npx hardhat task0 --undefinedParam <value>";
436447

0 commit comments

Comments
 (0)