Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error printing for Hardhat v3 #5455

Merged
merged 18 commits into from
Jul 1, 2024
Merged

Error printing for Hardhat v3 #5455

merged 18 commits into from
Jul 1, 2024

Conversation

schaable
Copy link
Member

Errors are formatted and printed based on their category. Errors may belong to one of these categories:

1. Hardhat errors: these are thrown from core or hardhat packages.
2. Hardhat plugin errors: these are thrown from official Hardhat plugins, such as hardhat-ignition. Technically, this category would also include built-in plugins like run, but since we’re not adding the pluginId property to their descriptors, they fall into category 1 (Hardhat errors).
3. Hardhat community plugin errors: these are thrown from community-developed plugins that use the HardhatPluginError, such as hardhat-deploy.
4. Other errors: this category includes any other errors that don't fall into the above categories. This includes instances of Error, as well as objects or strings.

Doc: https://www.notion.so/nomicfoundation/Design-doc-for-error-messages-2d49562c43de497d8241d8b024fe83b2#851e84f778c04437a5953c5f98a0b6d6

Screenshots:
(ignore the Time to run the task.. messages)

Hardhat errors:
hardhat-core

Hardhat plugin errors (added pluginId to the run descriptor, as we don't have any):
hardhat-plugin

Hardhat community plugin errors:
community-plugin

Other errors (Error instance and object):
unexpected-error
unknown-error

@schaable schaable added the v-next A Hardhat v3 development task label Jun 28, 2024
@schaable schaable requested a review from alcuadrado June 28, 2024 20:14
@schaable schaable self-assigned this Jun 28, 2024
Copy link

vercel bot commented Jun 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2024 5:15pm

Copy link

changeset-bot bot commented Jun 28, 2024

⚠️ No Changeset found

Latest commit: fca9000

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -0,0 +1,2 @@
export const HARDHAT_NAME = "Hardhat";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be merged with v-next/hardhat/src/internal/cli/init/constants.ts


main(process.argv.slice(2)).catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
printErrorMessages(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do this in main, so that that contains all the logic of the cli, and this file is just a bootstrap.

Also, process.exit() shouldn't be used, as it kills the process before giving it the opportunity to flush any i/o buffer (e.g. printing the error messages)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a0b79ac

print: (message: string) => void = console.error,
): void {
const showStackTraces =
process.argv.includes("--show-stack-traces") ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd pass this from main, so that we keep everything argv parsing there. It's a bit unexpected here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8111de5

Copy link
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just left a few comments

@schaable schaable merged commit 2fda776 into v-next Jul 1, 2024
51 checks passed
@schaable schaable deleted the error-printing branch July 1, 2024 18:58
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants