Skip to content

Commit 36fa7aa

Browse files
committed
Validate non-empty task id
1 parent a4bc7fd commit 36fa7aa

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

v-next/core/src/internal/tasks/builders.ts

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export class NewTaskDefinitionBuilderImplementation
3535
#action?: NewTaskActionFunction | string;
3636

3737
constructor(id: string | string[], description: string = "") {
38+
if (id.length === 0) {
39+
throw new HardhatError(
40+
HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK_ID,
41+
);
42+
}
43+
3844
this.#id = Array.isArray(id) ? id : [id];
3945
this.#description = description;
4046
}
@@ -288,6 +294,12 @@ export class TaskOverrideDefinitionBuilderImplementation
288294
#action?: TaskOverrideActionFunction | string;
289295

290296
constructor(id: string | string[]) {
297+
if (id.length === 0) {
298+
throw new HardhatError(
299+
HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK_ID,
300+
);
301+
}
302+
291303
this.#id = Array.isArray(id) ? id : [id];
292304
}
293305

v-next/core/test/internal/tasks/builders.ts

+46
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ describe("Task builders", () => {
4242
});
4343
});
4444

45+
describe("Task id validation", () => {
46+
it("should throw if the id is an empty string", () => {
47+
assert.throws(() => new NewTaskDefinitionBuilderImplementation(""), {
48+
name: "HardhatError",
49+
message:
50+
"HHE208: Task id cannot be an empty string or an empty array",
51+
});
52+
});
53+
54+
it("should throw if the array of ids is empty", () => {
55+
const ids: string[] = [];
56+
57+
assert.throws(() => new NewTaskDefinitionBuilderImplementation(ids), {
58+
name: "HardhatError",
59+
message:
60+
"HHE208: Task id cannot be an empty string or an empty array",
61+
});
62+
});
63+
});
64+
4565
describe("Adding an action", () => {
4666
it("should create a new task definition builder with an async function action", () => {
4767
const builder = new NewTaskDefinitionBuilderImplementation("task-id");
@@ -724,6 +744,32 @@ describe("Task builders", () => {
724744
});
725745
});
726746

747+
describe("Task id validation", () => {
748+
it("should throw if the id is an empty string", () => {
749+
assert.throws(
750+
() => new TaskOverrideDefinitionBuilderImplementation(""),
751+
{
752+
name: "HardhatError",
753+
message:
754+
"HHE208: Task id cannot be an empty string or an empty array",
755+
},
756+
);
757+
});
758+
759+
it("should throw if the array of ids is empty", () => {
760+
const ids: string[] = [];
761+
762+
assert.throws(
763+
() => new TaskOverrideDefinitionBuilderImplementation(ids),
764+
{
765+
name: "HardhatError",
766+
message:
767+
"HHE208: Task id cannot be an empty string or an empty array",
768+
},
769+
);
770+
});
771+
});
772+
727773
describe("Adding an action", () => {
728774
it("should create a task override definition builder with an async function action", () => {
729775
const builder = new TaskOverrideDefinitionBuilderImplementation(

0 commit comments

Comments
 (0)