Skip to content

Commit

Permalink
Merge pull request #6422 from NomicFoundation/unknown-build-profile
Browse files Browse the repository at this point in the history
Exception rather than clear message on unknown build profile
  • Loading branch information
ChristopherDedominici authored Mar 3, 2025
2 parents 25067ca + ccc5c77 commit 7ff285c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/many-wombats-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nomicfoundation/hardhat-errors": patch
"hardhat": patch
---

Improve error message when build profile is not found.
6 changes: 6 additions & 0 deletions v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,12 @@ Please check Hardhat's output for more details.`,
websiteTitle: "Resolution of not-exported npm file",
websiteDescription: `You are tying to resolve an npm file that is not exported by its package.`,
},
BUILD_PROFILE_NOT_FOUND: {
number: 1232,
messageTemplate: `The build profile "{buildProfileName}" is not defined in your Hardhat config`,
websiteTitle: "Build profile not defined",
websiteDescription: `The build profile you are trying to use is not defined in your Hardhat config.`,
},
},
VIEM: {
NETWORK_NOT_FOUND: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import type { SolidityBuildInfo } from "../../../../types/solidity.js";
import os from "node:os";
import path from "node:path";

import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
import {
assertHardhatInvariant,
HardhatError,
} from "@nomicfoundation/hardhat-errors";
import {
getAllDirectoriesMatching,
getAllFilesMatching,
Expand Down Expand Up @@ -306,6 +309,15 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {

const buildProfileName = options?.buildProfile ?? DEFAULT_BUILD_PROFILE;

if (this.#options.solidityConfig.profiles[buildProfileName] === undefined) {
throw new HardhatError(
HardhatError.ERRORS.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
{
buildProfileName,
},
);
}

log(`Using build profile ${buildProfileName}`);

const solcConfigSelector = new SolcConfigSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SolcConfigSelector {

/**
* Creates a new SolcConfigSelector that can be used to select the best solc
* configuration for subragraphs of the given dependency graph.
* configuration for subgraphs of the given dependency graph.
*
* All the queries are done in the context of the given dependency graph, and
* using the same build profile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import assert from "node:assert/strict";
import path from "node:path";
import { before, beforeEach, describe, it, mock } from "node:test";

import { HardhatError } from "@nomicfoundation/hardhat-errors";
import {
assertRejectsWithHardhatError,
getTmpDir,
useFixtureProject,
} from "@nomicfoundation/hardhat-test-utils";
Expand Down Expand Up @@ -375,6 +377,23 @@ describe(

assert.equal(runCompilationJobSpy.mock.callCount(), 0);
});

it("should throw when given a build profile that is not defined", async () => {
const rootFilePaths = await solidity.getRootFilePaths();

await assertRejectsWithHardhatError(
solidity.build(rootFilePaths, {
force: false,
mergeCompilationJobs: true,
quiet: true,
buildProfile: "not-defined",
}),
HardhatError.ERRORS.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
{
buildProfileName: "not-defined",
},
);
});
});
},
);

0 comments on commit 7ff285c

Please sign in to comment.