Skip to content

Improve compiler selection errors#7988

Merged
alcuadrado merged 16 commits intomainfrom
improve-compiler-selection-errors
Feb 27, 2026
Merged

Improve compiler selection errors#7988
alcuadrado merged 16 commits intomainfrom
improve-compiler-selection-errors

Conversation

@alcuadrado
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado commented Feb 22, 2026

Fixes #7748 by:

  • Running a better analysis of the error situation and presenting the users with more error cases
  • Using file system paths instead of inputSourceNames to display the files

It also makes working with results of SolidityBuildSystem#build and SolidityBuildSystem#getCompilationJobs simpler. /cc @kanej no more "reason" in ...

Replaces #7748

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 22, 2026

🦋 Changeset detected

Latest commit: df14a31

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@nomicfoundation/hardhat-typechain Patch
@nomicfoundation/hardhat-verify Patch
hardhat Patch

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request improves compiler selection error messages and API usability in the Hardhat Solidity build system. It addresses issue #7748 by providing more detailed, specific error messages when a Solidity file cannot be compiled due to version pragma incompatibilities, and it uses file system paths instead of input source names for better clarity. Additionally, it refactors the API to use discriminated unions with explicit success flags instead of relying on "reason" in ... checks, making the code safer and more maintainable.

Changes:

  • Introduced more granular error types with specific reasons (e.g., NO_COMPATIBLE_SOLC_VERSION_WITH_DEPENDENCY, OVERRIDDEN_SOLC_VERSION_INCOMPATIBLE_WITH_DEPENDENCY, NO_COMPATIBLE_SOLC_VERSION_FOR_TRANSITIVE_IMPORT_PATH)
  • Refactored return types to use discriminated unions with explicit success fields
  • Added isSuccessfulBuildResult() helper method to the SolidityBuildSystem interface for type-safe result checking
  • Updated error messages to display file system paths instead of input source names, improving readability for users
  • Enhanced error detection algorithm to identify the specific source of incompatibility in dependency trees

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
v-next/hardhat/src/types/solidity/build-system.ts Added new error reason enums, refactored error interfaces to use discriminated unions with success: false, added success: true to GetCompilationJobsResult, and defined isSuccessfulBuildResult method signature
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts Refactored return types to include success discriminant, enhanced error detection logic to identify specific incompatibility scenarios, updated error messages to use file system paths via shortenPath()
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts Implemented isSuccessfulBuildResult() method, updated result checks from "reason" in ... to !result.success, added success: true to returned compilation job results
v-next/hardhat/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts Implemented isSuccessfulBuildResult() in lazy build system wrapper using instanceof Map check
v-next/hardhat/src/internal/builtin-plugins/solidity/build-results.ts Updated throwIfSolidityBuildFailed() to accept SolidityBuildSystem parameter and use isSuccessfulBuildResult() helper
v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/build.ts Updated throwIfSolidityBuildFailed() call to pass solidity parameter
v-next/hardhat-verify/src/internal/artifacts.ts Updated error check from "reason" in ... to result.success
v-next/hardhat-typechain/src/internal/hook-handlers/solidity.ts Updated build result check to use isSuccessfulBuildResult() helper
v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts Added comprehensive test cases for new error scenarios, updated existing tests to expect discriminated union results with success field
v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/partial-compilation/*.ts Updated tests to use isSuccessfulBuildResult() and result.success checks
v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/integration/custom-compiler.ts Updated assertion helper to use isSuccessfulBuildResult()
v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/build-system.ts Updated test to use result.success check
.peer-bumps.json Added peer dependency bumps for hardhat-verify and hardhat-typechain due to API changes
.changeset/wet-lines-design.md Documented user-facing improvement to error messages
.changeset/flat-birds-start.md Documented API improvement for SolidityBuildSystem

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@ChristopherDedominici ChristopherDedominici left a comment

Choose a reason for hiding this comment

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

LGTM, only 2 minor comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docs needs to be updated according to the changes


return { compilationJobsPerFile, indexedIndividualJobs, cacheHits };
return {
success: true as const,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: I think as const can be removed

alcuadrado and others added 16 commits February 27, 2026 19:08
It now has a better algorithm that detects more cases, explaining them to the users. It also uses file-paths everywhere, instead of shoing the internal inputSourceNames.
…stem/solc-config-selection.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tem/solc-config-selection.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…tem/solc-config-selection.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alcuadrado alcuadrado force-pushed the improve-compiler-selection-errors branch from cc7152c to df14a31 Compare February 27, 2026 19:13
@alcuadrado alcuadrado enabled auto-merge February 27, 2026 19:13
@alcuadrado alcuadrado added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit f63b3d6 Feb 27, 2026
212 of 213 checks passed
@alcuadrado alcuadrado deleted the improve-compiler-selection-errors branch February 27, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when no solc version is compatible with a file

3 participants