MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / applyErrorMessageTemplate

Function applyErrorMessageTemplate

packages/hardhat-errors/src/errors.ts:260–285  ·  view source on GitHub ↗
(
  template: string,
  values: Record<string, ErrorMessageTemplateValue>,
)

Source from the content-addressed store, hash-verified

258 * @param values A map of variable names to their values.
259 */
260export function applyErrorMessageTemplate(
261 template: string,
262 values: Record<string, ErrorMessageTemplateValue>,
263): string {
264 return template.replaceAll(/{(.*?)}/g, (_match, variableName) => {
265 const rawValue = values[variableName];
266
267 if (rawValue === undefined) {
268 return "undefined";
269 }
270
271 if (rawValue === null) {
272 return "null";
273 }
274
275 if (typeof rawValue === "bigint") {
276 return `${rawValue}n`;
277 }
278
279 if (Array.isArray(rawValue)) {
280 return JSON.stringify(rawValue);
281 }
282
283 return rawValue.toString();
284 });
285}

Callers 2

errors.tsFile · 0.85
constructorMethod · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected