Skip to content

Commit faa9d72

Browse files
Task parameters are treated as unrecognized global parameters (#5373)
1 parent aad7796 commit faa9d72

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export async function parseGlobalArguments(
224224
usedCliArguments,
225225
parameters,
226226
globalArguments,
227+
true,
227228
);
228229

229230
return globalArguments;
@@ -357,6 +358,7 @@ function parseDoubleDashArgs(
357358
usedCliArguments: boolean[],
358359
parametersMap: Map<string, NamedTaskParameter | GlobalParameter>,
359360
argumentsMap: TaskArguments,
361+
ignoreUnknownParameter = false,
360362
) {
361363
for (let i = 0; i < cliArguments.length; i++) {
362364
if (usedCliArguments[i]) {
@@ -379,6 +381,11 @@ function parseDoubleDashArgs(
379381
const paramInfo = parametersMap.get(paramName);
380382

381383
if (paramInfo === undefined) {
384+
if (ignoreUnknownParameter === true) {
385+
continue;
386+
}
387+
388+
// Only throw an error when the parameter is not a global parameter, because it might be a parameter related to a task
382389
throw new HardhatError(
383390
HardhatError.ERRORS.ARGUMENTS.UNRECOGNIZED_NAMED_PARAM,
384391
{

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

+16
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ describe("main", function () {
214214
flag: true,
215215
});
216216
});
217+
218+
it("should not fail when a global parameter is not recognized (it might be a task parameter)", async function () {
219+
const command = "npx hardhat task --taskFlag <value>";
220+
221+
const cliArguments = command.split(" ").slice(2);
222+
const usedCliArguments = new Array(cliArguments.length).fill(false);
223+
224+
const globalArguments = await parseGlobalArguments(
225+
globalParamsIndex,
226+
cliArguments,
227+
usedCliArguments,
228+
);
229+
230+
assert.deepEqual(usedCliArguments, [false, false, false]);
231+
assert.deepEqual(globalArguments, {});
232+
});
217233
});
218234

219235
describe("parseTaskAndArguments", function () {

0 commit comments

Comments
 (0)