Expose Result type for task action success/failure signaling#8012
Expose Result type for task action success/failure signaling#8012
Result type for task action success/failure signaling#8012Conversation
🦋 Changeset detectedLatest commit: db636ad The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I'll review this better tomorrow, but I think using |
TaskResult type for task action success/failure signalingResult type for task action success/failure signaling
ac81572 to
f155727
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a public Result type (plus isResult, successResult, and errorResult) so task actions can explicitly signal success/failure to the Hardhat CLI, enabling the CLI to set process.exitCode = 1 when a task returns a failing result.
Changes:
- Add
Resulttype +isResult()guard andsuccessResult()/errorResult()helpers, and export them via package subpaths. - Update CLI main to detect failing
Resultreturns from tasks and setprocess.exitCode = 1. - Refactor Solidity resolver code/tests to use the shared
Resulttype and add new tests/fixture coverage for CLI behavior.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| v-next/hardhat/src/types/result.ts | Adds the new public Result type. |
| v-next/hardhat/src/utils/result.ts | Adds successResult, errorResult, and isResult. |
| v-next/hardhat/src/types/index.ts | Re-exports the new Result type from the types barrel. |
| v-next/hardhat/src/internal/cli/main.ts | Sets process.exitCode = 1 when a task returns a failing Result. |
| v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/types.ts | Removes local Result definition and imports shared Result. |
| v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/utils.ts | Updates Result import to shared public type. |
| v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/remapped-npm-packages-graph.ts | Updates Result import to shared public type. |
| v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts | Updates Result import to shared public type. |
| v-next/hardhat/package.json | Exposes ./types/result and ./utils/result export subpaths. |
| v-next/hardhat/test/utils/result.ts | Adds unit tests for factories and isResult. |
| v-next/hardhat/test/internal/cli/main.ts | Adds CLI tests asserting process.exitCode behavior based on returned Result. |
| v-next/hardhat/test/fixture-projects/cli/result/hardhat.config.ts | Adds fixture tasks returning various Result/non-Result values. |
| v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts | Updates tests to use shared Result type. |
| .changeset/nice-parrots-do.md | Adds a changeset entry for the patch release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
alcuadrado
left a comment
There was a problem hiding this comment.
There are some minor comments about naming, exports and a test, but pre-approving.
|
Also: on could create an issue to change all the builtin plugins' tasks to use Result, and update their tests so that they don't depend on |
|
And we should update the docs of |
This is already done in #8015
Done in db636ad and NomicFoundation/hardhat-website#228 |
Summary
Resultinterface that task actions can optionally return to signal success or failure to the CLItask.run()returns aResultwithsuccess: false, the CLI setsprocess.exitCode = 1undefinedor non-Resultvalues continue to work unchangedisResult()type guard andsuccessfulResult()/errorResult()factory helpers fromhardhat/utils/resultUsage
Docs: NomicFoundation/hardhat-website#228