Skip to content

Commit 399e449

Browse files
committed
improvement(plugins): use a HH error for duplicate id
Adds a plugin loading duplicate id error under the `general` category of Hardhat errors and uses that inside `resolve-plugin-list`.
1 parent d676fbc commit 399e449

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

v-next/core/src/internal/plugins/resolve-plugin-list.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
2+
13
import { HardhatPlugin } from "../../types/plugins.js";
24

35
/**
@@ -28,8 +30,9 @@ export function reverseTopologicalSort(
2830

2931
if (visited !== undefined) {
3032
if (visited !== plugin) {
31-
throw new Error(
32-
`Duplicated plugin id "${plugin.id}" found. Did you install multiple versions of the same plugin?`,
33+
throw new HardhatError(
34+
HardhatError.ERRORS.GENERAL.DUPLICATED_PLUGIN_ID,
35+
{ id: plugin.id },
3336
);
3437
}
3538

v-next/core/test/plugins/resolve-plugin-list.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import assert from "node:assert";
22
import { describe, it } from "node:test";
33

4+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
5+
46
import { resolvePluginList } from "../../src/internal/plugins/resolve-plugin-list.js";
57
import { HardhatPlugin } from "../../src/types/plugins.js";
68

@@ -106,14 +108,24 @@ describe("Plugins - resolve plugin list", () => {
106108
]);
107109
});
108110

109-
it("should error on different plugins with the same id", () => {
111+
it("should throw a HardhatError on finding different plugins with the same id", () => {
110112
const a = { id: "dup" };
111113
const copy = { id: "dup" };
112114

113115
assert.throws(
114116
() => resolvePluginList([a, copy]),
115-
/Duplicated plugin id "dup" found. Did you install multiple versions of the same plugin\?/,
116-
"Expected a duplicate is to be detected",
117+
118+
(err) => {
119+
assert(HardhatError.isHardhatError(err), "Expected a HardhatError");
120+
assert(
121+
/Duplicated plugin id "dup" found. Did you install multiple versions of the same plugin\?/.test(
122+
err.message,
123+
),
124+
);
125+
126+
return true;
127+
},
128+
"Expected a duplicate to be detected",
117129
);
118130
});
119131
});

v-next/hardhat-errors/src/descriptors.ts

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ Note that you don't need to do this every time you install a new dependency, but
104104
105105
Please double check the file path.`,
106106
},
107+
DUPLICATED_PLUGIN_ID: {
108+
number: 4,
109+
messageTemplate:
110+
'Duplicated plugin id "%id%" found. Did you install multiple versions of the same plugin?',
111+
websiteTitle: "Duplicated plugin id",
112+
websiteDescription: `While loading the plugins, two different plugins where found with the same id.
113+
114+
Please double check whether you have multiple versions of the same plugin installed.`,
115+
},
107116
},
108117
INTERNAL: {
109118
ASSERTION_ERROR: {

0 commit comments

Comments
 (0)