Skip to content

Commit

Permalink
Add the few missing HardhatError descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Sep 20, 2024
1 parent 409109e commit e0ff0b5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
34 changes: 27 additions & 7 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,32 @@ Please change your remapping to match the installed version, or installed the co
},
INVALID_NPM_IMPORT: {
number: 1013,
messageTemplate: `The import "{imporPath}" in "{from}" is treated as an npm import as it's first directory doesn't exist in your project, but it's syntax is not that of a valid npm import either.`,
messageTemplate: `The import "{importPath}" in "{from}" is treated as an npm import as it's first directory doesn't exist in your project, but it's syntax is not that of a valid npm import either.`,
websiteTitle: `Invalid npm import`,
websiteDescription: `You are trying to import a file that is not a valid npm import. Please double check that you are using the correct syntax.`,
},
INVALID_VERSION: {
ILLEGAL_PACKAGE_IMPORT: {
number: 1014,
messageTemplate: `The import "{importPath}" in "{from}" is not a legal import as it's trying to import a file outside of its package.`,
websiteTitle: `Illegal package import`,
websiteDescription: `One of your npm packages has a Solidity file that is trying to import a file outside of its package using a relative import. This is disabled for security reasons.`,
},
ILEGALL_PROJECT_IMPORT: {
number: 1015,
messageTemplate: `The import "{importPath}" in "{from}" is not a legal import as it's trying to import a file outside of the project.`,
websiteTitle: `Illegal project import`,
websiteDescription: `One of your Solidity files is trying to import a file outside of the Hardhat project using a relative import. This is disabled for security reasons.`,
},
ILLEGAL_PROJECT_IMPORT_AFTER_REMAPPING: {
number: 1016,
messageTemplate: `Applying the remapping "{remapping}" to the import "{importPath}" from "{from}" results in an invalid import "{remappedDirectImport}", as it's not a local file. If you are trying to remap into an npm module use the npm/ syntax instead.`,
websiteTitle: `Illegal project import after remapping`,
websiteDescription: `One of your Solidity files has an import which after applying a user remapping becomes an illegal import, as it tries to import a file outside of the project. This is disabled for security reasons.
If you are trying to remap into an npm module use the npm/ syntax instead.`,
},
INVALID_SOLC_VERSION: {
number: 1017,
messageTemplate: `Solidity version {version} is invalid or hasn't been released yet.
If you are certain it has been released, run "npx hardhat clean --global" and try again`,
Expand All @@ -803,7 +823,7 @@ If you are certain it has been released, run "npx hardhat clean --global" and tr
If you are certain it has been released, run \`npx hardhat clean --global\` and try again.`,
},
DOWNLOAD_FAILED: {
number: 1015,
number: 1018,
messageTemplate:
"Couldn't download compiler version {remoteVersion}. Please check your internet connection and try again.",
websiteTitle: "`solc` download failed",
Expand All @@ -812,7 +832,7 @@ If you are certain it has been released, run \`npx hardhat clean --global\` and
Please check your internet connection and try again.`,
},
VERSION_LIST_DOWNLOAD_FAILED: {
number: 1016,
number: 1019,
messageTemplate:
"Couldn't download compiler version list. Please check your internet connection and try again.",
websiteTitle: "Couldn't obtain `solc` version list",
Expand All @@ -821,7 +841,7 @@ Please check your internet connection and try again.`,
Please check your internet connection and try again.`,
},
INVALID_DOWNLOAD: {
number: 1017,
number: 1020,
messageTemplate: `Couldn't download compiler version {remoteVersion}: Checksum verification failed.
Please check your internet connection and try again.
Expand All @@ -835,7 +855,7 @@ Please check your internet connection and try again.
If this error persists, run \`npx hardhat clean --global\`.`,
},
CANT_RUN_NATIVE_COMPILER: {
number: 1018,
number: 1021,
messageTemplate: `A native version of solc failed to run.
If you are running MacOS, try installing Apple Rosetta.
Expand All @@ -849,7 +869,7 @@ If you are running MacOS, try installing Apple Rosetta.
If this error persists, run "npx hardhat clean --global".`,
},
CANT_RUN_SOLCJS_COMPILER: {
number: 1019,
number: 1022,
messageTemplate: `A wasm version of solc failed to run.
If this error persists, run "npx hardhat clean --global".`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ export class CompilerDownloaderImplementation implements CompilerDownloader {
const build = list.builds.find((b) => b.version === version);

if (build === undefined) {
throw new HardhatError(HardhatError.ERRORS.SOLIDITY.INVALID_VERSION, {
version,
});
throw new HardhatError(
HardhatError.ERRORS.SOLIDITY.INVALID_SOLC_VERSION,
{
version,
},
);
}

return build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,22 @@ export class ResolverImplementation implements Resolver {

if (from.type === ResolvedFileType.NPM_PACKGE_FILE) {
if (!directImport.startsWith(from.package.rootSourceName)) {
throw new Error(
`Invalid import ${importPath} from ${this.#shortenPath(from.path)}, trying to import outside of the package`,
throw new HardhatError(
HardhatError.ERRORS.SOLIDITY.ILLEGAL_PACKAGE_IMPORT,
{
importPath,
from: this.#shortenPath(from.path),
},
);
}
} else {
if (directImport.startsWith("../")) {
throw new Error(
`Invalid import ${importPath} from ${this.#shortenPath(from.path)}, trying to import outside of the project`,
throw new HardhatError(
HardhatError.ERRORS.SOLIDITY.ILEGALL_PROJECT_IMPORT,
{
importPath,
from: this.#shortenPath(from.path),
},
);
}
}
Expand Down Expand Up @@ -441,8 +449,14 @@ export class ResolverImplementation implements Resolver {
remappedDirectImport,
))
) {
throw new Error(
`Applying the remapping "${bestUserRemapping.rawFormat}" to the import ${importPath} from ${this.#shortenPath(from.path)} results in an invalid import ${remappedDirectImport}, as it's not a local files. If you are trying to remap into an npm module use the npm/ syntax instead.`,
throw new HardhatError(
HardhatError.ERRORS.SOLIDITY.ILLEGAL_PROJECT_IMPORT_AFTER_REMAPPING,
{
importPath,
from: this.#shortenPath(from.path),
remapping: bestUserRemapping.rawFormat,
remappedDirectImport,
},
);
}

Expand Down Expand Up @@ -551,7 +565,10 @@ export class ResolverImplementation implements Resolver {
const parsedDirectImport = this.#parseNpmDirectImport(directImport);

if (parsedDirectImport === undefined) {
throw new Error(`Invalid npm import ${directImport}`);
throw new HardhatError(HardhatError.ERRORS.SOLIDITY.INVALID_NPM_IMPORT, {
importPath,
from: this.#shortenPath(from.path),
});
}

const dependencyMapsKey =
Expand Down

0 comments on commit e0ff0b5

Please sign in to comment.