-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5198 from NomicFoundation/v-next-hardhat-errors
[v-next] Port `HardhatError`
- Loading branch information
Showing
15 changed files
with
804 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { createConfig } = require("../../config-v-next/eslint.cjs"); | ||
|
||
module.exports = createConfig(__filename, [ | ||
"src/index.ts", | ||
"src/other-entry-point.ts", | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Node modules | ||
/node_modules | ||
|
||
# Compilation output | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
/dist | ||
CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Nomic Foundation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Hardhat errors | ||
|
||
This packages has the definition of the error classes used by Hardhat, and the list of possible errors. | ||
|
||
This module exports: | ||
|
||
1. The error class `HardhatError`, which has a static field `ERRORS`, with the different `ErrorDescriptors` that it accepts. | ||
2. The interface `ErrorDescriptor`. | ||
3. The assertion helper `assertHardhatInvariant`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "@nomicfoundation/hardhat-errors", | ||
"version": "3.0.0", | ||
"description": "The different errors that Hardhat can throw", | ||
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-errors", | ||
"repository": "github:nomicfoundation/hardhat", | ||
"author": "Nomic Foundation", | ||
"license": "MIT", | ||
"type": "module", | ||
"types": "dist/src/index.d.ts", | ||
"exports": { | ||
".": "./dist/src/index.js" | ||
}, | ||
"keywords": [ | ||
"ethereum", | ||
"smart-contracts", | ||
"hardhat" | ||
], | ||
"scripts": { | ||
"lint": "pnpm prettier --check && pnpm eslint", | ||
"lint:fix": "pnpm prettier --write && pnpm eslint --fix", | ||
"eslint": "eslint 'src/**/*.ts' 'test/**/*.ts'", | ||
"prettier": "prettier \"**/*.{ts,js,md,json}\"", | ||
"test": "glob --cmd=\"node --import tsx/esm --test\" 'test/**/*.ts'", | ||
"test:github": "glob --cmd=\"node --import tsx/esm --test --test-reporter=@reporters/github --test-reporter-destination=stdout --test-reporter=spec --test-reporter-destination=stdout\" 'test/**/*.ts'", | ||
"pretest": "pnpm build", | ||
"build": "tsc --build .", | ||
"prepublishOnly": "pnpm build", | ||
"clean": "rimraf dist" | ||
}, | ||
"files": [ | ||
"dist/src/", | ||
"src/", | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"devDependencies": { | ||
"@nomicfoundation/hardhat-utils": "workspace:^3.0.0", | ||
"@nomicfoundation/eslint-plugin-hardhat-internal-rules": "workspace:^", | ||
"@nomicfoundation/eslint-plugin-slow-imports": "workspace:^", | ||
"@reporters/github": "^1.7.0", | ||
"@types/node": "^20.0.0", | ||
"@typescript-eslint/eslint-plugin": "^7.7.1", | ||
"@typescript-eslint/parser": "^7.7.1", | ||
"eslint": "8.57.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-import": "2.29.1", | ||
"eslint-plugin-no-only-tests": "3.1.0", | ||
"expect-type": "^0.19.0", | ||
"glob": "^10.3.12", | ||
"prettier": "3.2.5", | ||
"rimraf": "^5.0.5", | ||
"tsx": "^4.7.1", | ||
"typescript": "~5.4.0", | ||
"typescript-eslint": "7.7.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* A description of a kind of error that Hardhat can throw. | ||
*/ | ||
export interface ErrorDescriptor { | ||
/** | ||
* The error number, which should be unique. | ||
*/ | ||
number: number; | ||
|
||
/** | ||
* The id of the plugin that throws this error. | ||
*/ | ||
pluginId?: string; | ||
|
||
/** | ||
* A tempalte of the message of the error. | ||
* | ||
* This should be a short description. If possible, it should tell the user | ||
* how to solve their problem. | ||
* | ||
* @see The `applyErrorMessageTemplate` function. | ||
*/ | ||
messageTemplate: string; | ||
|
||
/** | ||
* `true` if this error should be reported | ||
*/ | ||
shouldBeReported?: true; | ||
|
||
/** | ||
* The title to use on the website section explaining this error, which can | ||
* use markdown. | ||
*/ | ||
websiteTitle: string; | ||
|
||
/** | ||
* The description to use on the website section explaining this error, which | ||
* can use markdown. | ||
*/ | ||
websiteDescription: string; | ||
} | ||
|
||
export const ERROR_CATEGORIES: { | ||
[categoryName: string]: { | ||
min: number; | ||
max: number; | ||
websiteTitle: string; | ||
}; | ||
} = { | ||
GENERAL: { min: 1, max: 99, websiteTitle: "General errors" }, | ||
INTERNAL: { min: 100, max: 199, websiteTitle: "Internal Hardhat errors" }, | ||
}; | ||
|
||
export const ERRORS = { | ||
GENERAL: { | ||
NOT_INSIDE_PROJECT: { | ||
number: 1, | ||
messageTemplate: "You are not inside a Hardhat project.", | ||
websiteTitle: "You are not inside a Hardhat project", | ||
websiteDescription: `You are trying to run Hardhat outside of a Hardhat project. | ||
You can learn how to use Hardhat by reading the [Getting Started guide](/hardhat-runner/docs/getting-started).`, | ||
}, | ||
}, | ||
INTERNAL: { | ||
ASSERTION_ERROR: { | ||
number: 100, | ||
messageTemplate: "An internal invariant was violated: %message%", | ||
websiteTitle: "Invariant violation", | ||
websiteDescription: `An internal invariant was violated. This is probably caused by a programming error in Hardhat or in one of the used plugins. | ||
Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us improve Hardhat.`, | ||
shouldBeReported: true, | ||
}, | ||
}, | ||
} satisfies { | ||
[category in keyof typeof ERROR_CATEGORIES]: { | ||
[name: string]: ErrorDescriptor; | ||
}; | ||
}; |
Oops, something went wrong.