Skip to content

Commit ced2371

Browse files
authored
Merge pull request #7113 from NomicFoundation/fix-error-descriptors-markdown
Improve error descriptors
2 parents 586fcfe + a657c61 commit ced2371

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

.changeset/silent-mice-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/hardhat-errors": patch
3+
---
4+
5+
General improvement of error messages.

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

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const ERROR_CATEGORIES: {
5454
min: 1,
5555
max: 9999,
5656
pluginId: undefined,
57-
websiteTitle: "Hardhat Core",
57+
websiteTitle: "Hardhat 3",
5858
CATEGORIES: {
5959
GENERAL: {
6060
min: 1,
@@ -445,8 +445,8 @@ Please add the property "type" with the value "module" in your package.json to e
445445
CONFIG_VARIABLE_FORMAT_MUST_INCLUDE_VARIABLE: {
446446
number: 19,
447447
messageTemplate: `The format string "{format}" must include {marker} marker`,
448-
websiteTitle: "Config variable format must include {variable}",
449-
websiteDescription: `The config variable format must include the string "{variable}", which will be replaced with the actual value of the variable.`,
448+
websiteTitle: "Config variable format must include \\{variable\\}",
449+
websiteDescription: `The config variable format must include the string "\\{variable\\}", which will be replaced with the actual value of the variable.`,
450450
},
451451
INVALID_FULLY_QUALIFIED_NAME: {
452452
number: 20,
@@ -1118,7 +1118,7 @@ Please check Hardhat's output for more details.`,
11181118
number: 911,
11191119
messageTemplate: `A wasm version of solc {version} is invalid. The compile function is not available.`,
11201120
websiteTitle: "Invalid solcjs compiler",
1121-
websiteDescription: `Hardhat successfully downloaded a WASM version of solc {version} but it is invalid. The compile function is missing.`,
1121+
websiteDescription: `Hardhat successfully downloaded a WASM version of solc but it is invalid. The compile function is missing.`,
11221122
},
11231123
BUILD_PROFILE_NOT_FOUND: {
11241124
number: 912,
@@ -1977,11 +1977,13 @@ Please try again later.`,
19771977
websiteTitle: "Network not found",
19781978
websiteDescription: `No network with the specified chain id was found. You can override the chain by passing it as a parameter to the client getter:
19791979
1980+
\`\`\`ts
19801981
import { someChain } from "viem/chains";
19811982
const client = await hre.viem.getPublicClient({
19821983
chain: someChain,
19831984
...
19841985
});
1986+
\`\`\`
19851987
19861988
You can find a list of supported networks here: https://github.com/wevm/viem/blob/main/src/chains/index.ts`,
19871989
},
@@ -2002,12 +2004,15 @@ Please ensure you're using one of the supported networks.`,
20022004
20032005
To resolve this, make sure to add an account to the specified network in the Hardhat config. Alternatively, you can set a custom wallet client by passing it as a parameter in the relevant function:
20042006
2007+
\`\`\`ts
20052008
const networkConnection = await hre.network.connect(...);
20062009
const walletClient = await networkConnection.viem.getWalletClient(address);
20072010
20082011
await networkConnection.viem.deployContract(contractName, constructorArgs, { walletClient });
20092012
await networkConnection.viem.sendDeploymentTransaction(contractName, constructorArgs, { walletClient });
2010-
await networkConnection.viem.getContractAt(contractName, address, { walletClient });`,
2013+
await networkConnection.viem.getContractAt(contractName, address, { walletClient });
2014+
\`\`\`
2015+
`,
20112016
},
20122017
LINKING_CONTRACT_ERROR: {
20132018
number: 40003,
@@ -2237,9 +2242,9 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
22372242
messageTemplate:
22382243
"The .revertedWithCustomError matcher expects two arguments: the contract and the custom error name. Arguments should be asserted with the .withArgs helper.",
22392244
websiteTitle:
2240-
"Invalid arguments length for the .revertedWithCustomError matcher",
2245+
"Invalid arguments length for the .revertedWithCustomError matcher",
22412246
websiteDescription:
2242-
"Invalid arguments length for the .revertedWithCustomError matcher",
2247+
"Invalid arguments length for the .revertedWithCustomError matcher",
22432248
},
22442249
WITH_ARGS_FORBIDDEN: {
22452250
number: 70011,
@@ -2345,7 +2350,9 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
23452350
websiteTitle: "Network not supported",
23462351
websiteDescription: `The network is not supported by hardhat-verify. To see the list of supported networks, run:
23472352
2348-
npx hardhat verify --list-networks
2353+
\`\`\`sh
2354+
npx hardhat verify --list-networks
2355+
\`\`\`
23492356
23502357
To add support for a new network, see https://hardhat.org/verify-custom-networks`,
23512358
},
@@ -2354,17 +2361,19 @@ To add support for a new network, see https://hardhat.org/verify-custom-networks
23542361
messageTemplate: `The request to {url} failed with the message "{errorMessage}". This error comes from {name}, not Hardhat.`,
23552362
websiteTitle: "Explorer request failed",
23562363
websiteDescription: `The request to the explorer failed.
2364+
23572365
- Verify that the URL is correct.
2358-
- Ensure the {name} service is up and reachable.
2366+
- Ensure the service is up and reachable.
23592367
- Check your network connection and try again.`,
23602368
},
23612369
EXPLORER_REQUEST_STATUS_CODE_ERROR: {
23622370
number: 80002,
23632371
messageTemplate: `The request to {url} returned a non-success status code {statusCode}: "{errorMessage}". (This response comes from {name}, not Hardhat.)`,
23642372
websiteTitle: "Explorer request status code error",
23652373
websiteDescription: `The request to the explorer returned a non-success status code.
2374+
23662375
- Verify that the URL is correct.
2367-
- Ensure the {name} service is up and reachable.
2376+
- Ensure the service is up and reachable.
23682377
- Check your network connection and try again.`,
23692378
},
23702379
SOLC_VERSION_NOT_SUPPORTED: {
@@ -2388,6 +2397,7 @@ Please verify the address and selected network, and try again.`,
23882397
websiteDescription: `The Solidity compiler version used to compile the deployed contract does not match any of the versions configured in your Hardhat project.
23892398
23902399
This mismatch may indicate:
2400+
23912401
- You're not on the same commit that was used to deploy the contract.
23922402
- The compiler version in your Hardhat config is incorrect.
23932403
- The address provided is not the deployed contract.
@@ -2411,6 +2421,7 @@ This mismatch may indicate:
24112421
websiteTitle: "Build info compiler version mismatch",
24122422
websiteDescription: `The compiler version in the build info does not match the version encoded in the deployed bytecode.
24132423
Possible causes:
2424+
24142425
- Compiler settings were changed after deployment.
24152426
- The contract address is incorrect.
24162427
- The selected network is incorrect.`,
@@ -2422,7 +2433,8 @@ Possible causes:
24222433
websiteDescription: `The bytecode at the specified address did not match the expected contract.
24232434
24242435
Possible causes:
2425-
- Your artifacts are outdated or missing; try running npx hardhat compile --force --buildProfile production.
2436+
2437+
- Your artifacts are outdated or missing; try running \`npx hardhat compile --force --buildProfile production\`.
24262438
- The contract code was modified after deployment.
24272439
- Compiler settings (optimizer, EVM version, etc.) changed after deployment.
24282440
- The provided address is incorrect.
@@ -2433,11 +2445,14 @@ Possible causes:
24332445
messageTemplate: `More than one contract matches the deployed bytecode:
24342446
{fqnList}
24352447
2436-
Specify the exact contract using the "--contract" flag.`,
2448+
Specify the exact contract using the \`--contract\` flag.`,
24372449
websiteTitle: "Multiple contract matches",
2438-
websiteDescription: `The deployed bytecode matches multiple compiled contracts. Specify the exact contract using the "--contract" flag. For example:
2439-
2440-
npx hardhat verify --contract contracts/Example.sol:ExampleContract <other args>`,
2450+
websiteDescription: `The deployed bytecode matches multiple compiled contracts. Specify the exact contract using the \`--contract\` flag. For example:
2451+
2452+
\`\`\`sh
2453+
npx hardhat verify --contract contracts/Example.sol:ExampleContract <other args>
2454+
\`\`\`
2455+
`,
24412456
},
24422457
INVALID_LIBRARY_ADDRESS: {
24432458
number: 80011,
@@ -2455,7 +2470,10 @@ npx hardhat verify --contract contracts/Example.sol:ExampleContract <other args>
24552470
24562471
If the contract uses external libraries, verify that the provided name matches the fully qualified name (FQN) of one of them, such as:
24572472
2458-
contracts/Math.sol:SafeMath`,
2473+
\`\`\`
2474+
contracts/Math.sol:SafeMath
2475+
\`\`\`
2476+
`,
24592477
},
24602478
LIBRARY_MULTIPLE_MATCHES: {
24612479
number: 80013,
@@ -2469,15 +2487,18 @@ To fix this, specify one of these fully qualified library names and try again.`,
24692487
24702488
To resolve the ambiguity, provide the fully qualified library name in the format:
24712489
2472-
path/to/LibraryFile.sol:LibraryName`,
2490+
\`\`\`
2491+
path/to/LibraryFile.sol:LibraryName
2492+
\`\`\`
2493+
`,
24732494
},
24742495
DUPLICATED_LIBRARY: {
24752496
number: 80014,
24762497
messageTemplate: `The library name "{library}" and its fully qualified name "{libraryFqn}" refer to the same library.
24772498
24782499
To fix this, remove one of them and try again.`,
24792500
websiteTitle: "Duplicated library entry",
2480-
websiteDescription: `The same library was specified more than once using both its short name and fully qualified name (FQN) in the "--libraries" option.
2501+
websiteDescription: `The same library was specified more than once using both its short name and fully qualified name (FQN) in the \`--libraries\` option.
24812502
24822503
Only one form should be used for each library. Remove one of the entries and try again.`,
24832504
},
@@ -2601,6 +2622,7 @@ Block explorer information is missing in your chain descriptor configuration.
26012622
To enable contract verification, add an entry for the verification provider in the blockExplorers field of the relevant chain descriptor.
26022623
You can override the default chain descriptor by providing your own chainDescriptors object in the Hardhat config, with the following structure:
26032624
2625+
\`\`\`
26042626
chainDescriptors: {
26052627
<chainId>: {
26062628
name: <name>,
@@ -2610,7 +2632,7 @@ chainDescriptors: {
26102632
}
26112633
}
26122634
}
2613-
2635+
\`\`\`
26142636
`,
26152637
},
26162638
ADDRESS_NOT_A_CONTRACT: {
@@ -2625,6 +2647,7 @@ Please verify the address and network, and try again later if necessary.`,
26252647
messageTemplate: `The {verificationProvider} API key is empty.`,
26262648
websiteTitle: "Block explorer API key is empty",
26272649
websiteDescription: `The provided API key for the block explorer is empty. This can happen in the following cases:
2650+
26282651
- No "apiKey" field is configured in the hardhat config.
26292652
- The "apiKey" is explicitly set to an empty string in the Hardhat config.
26302653
- The "apiKey" is assigned to a config variable that resolves to an empty string at runtime.
@@ -2655,7 +2678,10 @@ To resolve this, set a valid non-empty API key in your Hardhat config, then try
26552678
26562679
Example:
26572680
2658-
export default ["arg1", "arg2", ...];`,
2681+
\`\`\`ts
2682+
export default ["arg1", "arg2", ...];
2683+
\`\`\`
2684+
`,
26592685
},
26602686
MODULE_NOT_FOUND: {
26612687
number: 80103,
@@ -2685,7 +2711,9 @@ export default ["arg1", "arg2", ...];`,
26852711
26862712
Example:
26872713
2688-
export default { lib1: "0x...", lib2: "0x...", ... };`,
2714+
\`\`\`ts
2715+
export default { lib1: "0x...", lib2: "0x...", ... };
2716+
\`\`\``,
26892717
},
26902718
INVALID_VERIFICATION_PROVIDER: {
26912719
number: 80107,

0 commit comments

Comments
 (0)