Skip to content

Commit

Permalink
Merge pull request #5460 from NomicFoundation/isolate-build-system
Browse files Browse the repository at this point in the history
Isolate the build-system package errors
  • Loading branch information
alcuadrado authored Jul 1, 2024
2 parents a83229b + 0344584 commit 35583c9
Show file tree
Hide file tree
Showing 20 changed files with 864 additions and 787 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from "node:assert/strict";
import { before, describe, it } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { ResolvedConfigurationVariableImplementation } from "../../../src/internal/configuration-variables.js";
import { HookManagerImplementation } from "../../../src/internal/hook-manager.js";
import { UserInterruptionManagerImplementation } from "../../../src/internal/user-interruptions.js";
Expand Down Expand Up @@ -55,7 +57,7 @@ describe("ResolvedConfigurationVariable", () => {

await assert.rejects(
variable.get(),
"Configuration variable not found as an env variable",
new HardhatError(HardhatError.ERRORS.GENERAL.ENV_VAR_NOT_FOUND),
);
});

Expand Down Expand Up @@ -97,7 +99,12 @@ describe("ResolvedConfigurationVariable", () => {

process.env.foo = "not a url";

await assert.rejects(variable.getUrl(), "Invalid URL: not a url");
await assert.rejects(
variable.getUrl(),
new HardhatError(HardhatError.ERRORS.GENERAL.INVALID_URL, {
url: "not a url",
}),
);

delete process.env.foo;
});
Expand All @@ -123,7 +130,12 @@ describe("ResolvedConfigurationVariable", () => {

process.env.foo = "not a bigint";

await assert.rejects(variable.getBigInt(), "Invalid BigInt: not a bigint");
await assert.rejects(
variable.getBigInt(),
new HardhatError(HardhatError.ERRORS.GENERAL.INVALID_BIGINT, {
value: "not a bigint",
}),
);

delete process.env.foo;
});
Expand Down
15 changes: 10 additions & 5 deletions v-next/core/test/internal/hook-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type { UserInterruptionManager } from "../../src/types/user-interruptions
import assert from "node:assert/strict";
import { describe, it, beforeEach } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { HookManagerImplementation } from "../../src/internal/hook-manager.js";
import { UserInterruptionManagerImplementation } from "../../src/internal/user-interruptions.js";

Expand Down Expand Up @@ -269,11 +271,14 @@ describe("HookManager", () => {
return {};
},
),
{
name: "HardhatError",
message:
'HHE1300: Plugin "example" hook factory for "config" is not a valid file:// URL: ./fixture-plugins/config-plugin.js.',
},
new HardhatError(
HardhatError.ERRORS.HOOKS.INVALID_HOOK_FACTORY_PATH,
{
hookCategoryName: "config",
pluginId: "example",
path: "./fixture-plugins/config-plugin.js",
},
),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { HardhatPlugin } from "../../../src/types/plugins.js";
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { detectPluginNpmDependencyProblems } from "../../../src/internal/plugins/detect-plugin-npm-dependency-problems.js";

describe("Plugins - detect npm dependency problems", () => {
Expand Down Expand Up @@ -52,10 +54,9 @@ describe("Plugins - detect npm dependency problems", () => {
plugin,
nonInstalledPackageProjectFixture,
),
{
name: "HardhatError",
message: 'HHE1200: Plugin "example-plugin" is not installed.',
},
new HardhatError(HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, {
pluginId: "example-plugin",
}),
);
});
});
Expand All @@ -79,11 +80,10 @@ describe("Plugins - detect npm dependency problems", () => {

await assert.rejects(
detectPluginNpmDependencyProblems(plugin, notInstalledPeerDepFixture),
{
name: "HardhatError",
message:
'HHE1201: Plugin "example-plugin" is missing a peer dependency "peer2".',
},
new HardhatError(
HardhatError.ERRORS.PLUGINS.PLUGIN_MISSING_DEPENDENCY,
{ pluginId: "example-plugin", peerDependencyName: "peer2" },
),
);
});
});
Expand Down Expand Up @@ -113,11 +113,15 @@ describe("Plugins - detect npm dependency problems", () => {
plugin,
peerDepWithWrongVersionFixture,
),
{
name: "HardhatError",
message:
'HHE1202: Plugin "example-plugin" has a peer dependency "peer2" with expected version "^1.0.0" but the installed version is "2.0.0".',
},
new HardhatError(
HardhatError.ERRORS.PLUGINS.DEPENDENCY_VERSION_MISMATCH,
{
pluginId: "example-plugin",
peerDependencyName: "peer2",
expectedVersion: "^1.0.0",
installedVersion: "2.0.0",
},
),
);
});
});
Expand Down
25 changes: 12 additions & 13 deletions v-next/core/test/internal/plugins/resolve-plugin-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { HardhatPlugin } from "../../../src/types/plugins.js";
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { resolvePluginList } from "../../../src/internal/plugins/resolve-plugin-list.js";

describe("Plugins - resolve plugin list", () => {
Expand Down Expand Up @@ -149,11 +151,9 @@ describe("Plugins - resolve plugin list", () => {

await assert.rejects(
async () => resolvePluginList([a, copy], installedPackageFixture),
{
name: "HardhatError",
message:
'HHE4: Duplicated plugin id "dup" found. Did you install multiple versions of the same plugin?',
},
new HardhatError(HardhatError.ERRORS.GENERAL.DUPLICATED_PLUGIN_ID, {
id: "dup",
}),
);
});

Expand All @@ -171,10 +171,10 @@ describe("Plugins - resolve plugin list", () => {

await assert.rejects(
async () => resolvePluginList([plugin], installedPackageFixture),
{
name: "HardhatError",
message: 'HHE1203: Plugin "plugin" dependency could not be loaded.',
},
new HardhatError(
HardhatError.ERRORS.PLUGINS.PLUGIN_DEPENDENCY_FAILED_LOAD,
{ pluginId: plugin.id },
),
);
});

Expand All @@ -195,10 +195,9 @@ describe("Plugins - resolve plugin list", () => {

await assert.rejects(
async () => resolvePluginList([plugin], notInstalledPackageFixture),
{
name: "HardhatError",
message: 'HHE1200: Plugin "example" is not installed.',
},
new HardhatError(HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, {
pluginId: "example",
}),
);
});
});
Expand Down
Loading

0 comments on commit 35583c9

Please sign in to comment.