Skip to content

Commit 1b4dafb

Browse files
committed
Add validations to buildGlobalParameterMap
1 parent 5fcb380 commit 1b4dafb

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

v-next/core/src/internal/global-parameters.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,27 @@ export function buildGlobalParameterMap(
3333
continue;
3434
}
3535

36-
for (const [name, param] of Object.entries(plugin.globalParameters)) {
37-
// TODO: Validate name casing
38-
// TODO: Validate default value matches with type
39-
// TODO: Validate that the name is not one of the reserved ones in parameters.ts
40-
41-
const existingByName = globalParametersIndex.get(name);
42-
36+
for (const param of plugin.globalParameters) {
37+
const existingByName = globalParametersIndex.get(param.name);
4338
if (existingByName !== undefined) {
44-
throw new Error(
45-
`Plugin ${plugin.id} is trying to define the global parameter ${name} but it is already defined by plugin ${existingByName.pluginId}`,
39+
throw new HardhatError(
40+
HardhatError.ERRORS.GENERAL.GLOBAL_PARAMETER_ALREADY_DEFINED,
41+
{
42+
plugin: plugin.id,
43+
globalParameter: param.name,
44+
definedByPlugin: existingByName.pluginId,
45+
},
4646
);
4747
}
4848

49+
const validatedGlobalParam = buildGlobalParameterDefinition(param);
50+
4951
const indexEntry = {
5052
pluginId: plugin.id,
51-
param,
53+
param: validatedGlobalParam,
5254
};
5355

54-
globalParametersIndex.set(param.name, indexEntry);
56+
globalParametersIndex.set(validatedGlobalParam.name, indexEntry);
5557
}
5658
}
5759

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

+8
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ Please double check whether you have multiple versions of the same plugin instal
162162
websiteTitle: "Invalid BigInt",
163163
websiteDescription: `Given value was not a valid BigInt.`,
164164
},
165+
GLOBAL_PARAMETER_ALREADY_DEFINED: {
166+
number: 12,
167+
messageTemplate:
168+
"Plugin {plugin} is trying to define the global parameter {globalParameter} but it is already defined by plugin {definedByPlugin}",
169+
websiteTitle: "Global parameter already defined",
170+
websiteDescription:
171+
"The global parameter is already defined by another plugin. Please ensure that global parameters are uniquely named to avoid conflicts.",
172+
},
165173
},
166174
INTERNAL: {
167175
ASSERTION_ERROR: {

0 commit comments

Comments
 (0)