Skip to content

Commit

Permalink
Merge pull request #711 from mabsattar/processfix
Browse files Browse the repository at this point in the history
Processfix
  • Loading branch information
alcuadrado authored Apr 1, 2024
2 parents 749d833 + 568fe6a commit 48db054
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/ens/scripts/deploy-ens.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
process.exitCode = 1;
});
89 changes: 51 additions & 38 deletions packages/hardhat-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import {
readFile,
} from "fs-extra";
import { extendConfig, extendEnvironment, scope } from "hardhat/config";
import {
HardhatPluginError,
NomicLabsHardhatPluginError,
} from "hardhat/plugins";
import { NomicLabsHardhatPluginError } from "hardhat/plugins";
import path from "path";

import "./type-extensions";
Expand Down Expand Up @@ -70,7 +67,7 @@ extendEnvironment((hre) => {
(hre as any).ignition = {
type: "stub",
deploy: () => {
throw new HardhatPluginError(
throw new NomicLabsHardhatPluginError(
"hardhat-ignition",
"Please install either `@nomicfoundation/hardhat-ignition-viem` or `@nomicfoundation/hardhat-ignition-ethers` to use Ignition in your Hardhat tests"
);
Expand Down Expand Up @@ -210,18 +207,16 @@ ignitionScope

if (reset) {
if (deploymentDir === undefined) {
console.warn(
throw new NomicLabsHardhatPluginError(
"@nomicfoundation/hardhat-ignition",
"Deploy cancelled: Cannot reset deployment on ephemeral Hardhat network"
);

process.exit(1);
} else {
await rm(deploymentDir, { recursive: true, force: true });
}
}

if (strategyName !== "basic" && strategyName !== "create2") {
require("hardhat/plugins") as typeof import("hardhat/plugins");
throw new NomicLabsHardhatPluginError(
"hardhat-ignition",
"Invalid strategy name, must be either 'basic' or 'create2'"
Expand All @@ -233,8 +228,10 @@ ignitionScope
const userModule = loadModule(hre.config.paths.ignition, modulePath);

if (userModule === undefined) {
console.warn("No Ignition modules found");
process.exit(1);
throw new NomicLabsHardhatPluginError(
"@nomicfoundation/hardhat-ignition",
"No Ignition modules found"
);
}

let parameters: DeploymentParameters | undefined;
Expand Down Expand Up @@ -288,7 +285,7 @@ ignitionScope
}

if (result.type !== "SUCCESSFUL_DEPLOYMENT") {
process.exit(1);
process.exitCode = 1;
}
} catch (e) {
if (e instanceof IgnitionError && shouldBeHardhatPluginError(e)) {
Expand Down Expand Up @@ -330,32 +327,34 @@ ignitionScope
const userModule = loadModule(hre.config.paths.ignition, modulePath);

if (userModule === undefined) {
console.warn("No Ignition modules found");
process.exit(1);
}

try {
const serializedIgnitionModule =
IgnitionModuleSerializer.serialize(userModule);
throw new NomicLabsHardhatPluginError(
"@nomicfoundation/hardhat-ignition",
"No Ignition modules found"
);
} else {
try {
const serializedIgnitionModule =
IgnitionModuleSerializer.serialize(userModule);

const batchInfo = batches(userModule);
const batchInfo = batches(userModule);

await writeVisualization(
{ module: serializedIgnitionModule, batches: batchInfo },
{
cacheDir: hre.config.paths.cache,
}
);
} catch (e) {
if (e instanceof IgnitionError && shouldBeHardhatPluginError(e)) {
throw new NomicLabsHardhatPluginError(
"hardhat-ignition",
e.message,
e
await writeVisualization(
{ module: serializedIgnitionModule, batches: batchInfo },
{
cacheDir: hre.config.paths.cache,
}
);
}
} catch (e) {
if (e instanceof IgnitionError && shouldBeHardhatPluginError(e)) {
throw new NomicLabsHardhatPluginError(
"hardhat-ignition",
e.message,
e
);
}

throw e;
throw e;
}
}

if (!noOpen) {
Expand Down Expand Up @@ -582,8 +581,15 @@ async function resolveConfigPath(
throw e;
}

console.warn(`Could not parse parameters from ${filepath}`);
process.exit(1);
if (e instanceof Error) {
throw new NomicLabsHardhatPluginError(
"@nomicfoundation/hardhat-ignition",
`Could not parse parameters from ${filepath}`,
e
);
}

throw e;
}
}

Expand All @@ -595,7 +601,14 @@ function resolveParametersString(paramString: string): DeploymentParameters {
throw e;
}

console.warn(`Could not parse JSON parameters`);
process.exit(1);
if (e instanceof Error) {
throw new NomicLabsHardhatPluginError(
"@nomicfoundation/hardhat-ignition",
"Could not parse JSON parameters",
e
);
}

throw e;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SerializedIgnitionModule } from "@nomicfoundation/ignition-core";
import { ensureDir, pathExists, readFile, writeFile } from "fs-extra";
import { NomicLabsHardhatPluginError } from "hardhat/plugins";
import path from "path";

export async function writeVisualization(
Expand All @@ -17,8 +18,10 @@ export async function writeVisualization(
const templateDirExists = await pathExists(templateDir);

if (!templateDirExists) {
console.warn(`Unable to find template directory: ${templateDir}`);
process.exit(1);
throw new NomicLabsHardhatPluginError(
"@nomicfouncation/hardhat-ignition",
`Unable to find template directory: ${templateDir}`
);
}

const visualizationDir = path.join(cacheDir, "visualization");
Expand Down

0 comments on commit 48db054

Please sign in to comment.