Skip to content

Commit d95cbd5

Browse files
Merge pull request #6422 from NomicFoundation/unknown-build-profile
Exception rather than clear message on unknown build profile
2 parents 614908b + ccc5c77 commit d95cbd5

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

.changeset/many-wombats-grin.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-errors": patch
3+
"hardhat": patch
4+
---
5+
6+
Improve error message when build profile is not found.

v-next/hardhat-errors/src/descriptors.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,12 @@ Please check Hardhat's output for more details.`,
11921192
websiteTitle: "Resolution of not-exported npm file",
11931193
websiteDescription: `You are tying to resolve an npm file that is not exported by its package.`,
11941194
},
1195+
BUILD_PROFILE_NOT_FOUND: {
1196+
number: 1232,
1197+
messageTemplate: `The build profile "{buildProfileName}" is not defined in your Hardhat config`,
1198+
websiteTitle: "Build profile not defined",
1199+
websiteDescription: `The build profile you are trying to use is not defined in your Hardhat config.`,
1200+
},
11951201
},
11961202
VIEM: {
11971203
NETWORK_NOT_FOUND: {

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import type { SolidityBuildInfo } from "../../../../types/solidity.js";
2121
import os from "node:os";
2222
import path from "node:path";
2323

24-
import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors";
24+
import {
25+
assertHardhatInvariant,
26+
HardhatError,
27+
} from "@nomicfoundation/hardhat-errors";
2528
import {
2629
getAllDirectoriesMatching,
2730
getAllFilesMatching,
@@ -306,6 +309,15 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
306309

307310
const buildProfileName = options?.buildProfile ?? DEFAULT_BUILD_PROFILE;
308311

312+
if (this.#options.solidityConfig.profiles[buildProfileName] === undefined) {
313+
throw new HardhatError(
314+
HardhatError.ERRORS.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
315+
{
316+
buildProfileName,
317+
},
318+
);
319+
}
320+
309321
log(`Using build profile ${buildProfileName}`);
310322

311323
const solcConfigSelector = new SolcConfigSelector(

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SolcConfigSelector {
1818

1919
/**
2020
* Creates a new SolcConfigSelector that can be used to select the best solc
21-
* configuration for subragraphs of the given dependency graph.
21+
* configuration for subgraphs of the given dependency graph.
2222
*
2323
* All the queries are done in the context of the given dependency graph, and
2424
* using the same build profile.

v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/build-system.ts

+19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import assert from "node:assert/strict";
99
import path from "node:path";
1010
import { before, beforeEach, describe, it, mock } from "node:test";
1111

12+
import { HardhatError } from "@nomicfoundation/hardhat-errors";
1213
import {
14+
assertRejectsWithHardhatError,
1315
getTmpDir,
1416
useFixtureProject,
1517
} from "@nomicfoundation/hardhat-test-utils";
@@ -375,6 +377,23 @@ describe(
375377

376378
assert.equal(runCompilationJobSpy.mock.callCount(), 0);
377379
});
380+
381+
it("should throw when given a build profile that is not defined", async () => {
382+
const rootFilePaths = await solidity.getRootFilePaths();
383+
384+
await assertRejectsWithHardhatError(
385+
solidity.build(rootFilePaths, {
386+
force: false,
387+
mergeCompilationJobs: true,
388+
quiet: true,
389+
buildProfile: "not-defined",
390+
}),
391+
HardhatError.ERRORS.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
392+
{
393+
buildProfileName: "not-defined",
394+
},
395+
);
396+
});
378397
});
379398
},
380399
);

0 commit comments

Comments
 (0)