Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builder): error when a dependency input cannot be found. #1360

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/builder/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class ChainDefinition {
readonly dependencyFor = new Map<string, string>();
readonly resolvedDependencies = new Map<string, string[]>();

readonly danglingDependencies = new Set<`${string}:${string}`>();

constructor(def: RawChainDefinition, sensitiveDependencies = false) {
debug('begin chain def init');
this.raw = def;
Expand Down Expand Up @@ -355,8 +357,9 @@ export class ChainDefinition {
debug(`deps: ${node} consumes ${input}`);
if (this.dependencyFor.has(input)) {
deps.push(this.dependencyFor.get(input)!);
} else if (!input.startsWith('settings.')) {
} else {
debug(`WARNING: dependency ${input} not found for operation ${node}`);
this.danglingDependencies.add(`${input}:${node}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type { CannonLoader } from './loader';
export { IPFSLoader, InMemoryLoader } from './loader';
export { decodeTxError, renderTrace, findContract } from './trace';
export type { TraceEntry } from './trace';
export { traceActions } from './error';
export { traceActions, CannonError } from './error';
export { prepareMulticall } from './multicall';

// prevent dumb bugs
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/util/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { parseSettings } from './params';
import { pickAnvilOptions } from './anvil';
import { setDebugLevel } from './debug-level';
import { ProviderAction, resolveProvider, isURL, getChainIdFromRpcUrl } from './provider';

import { CannonError } from '@usecannon/builder';
import { bold, italic } from 'chalk';
const debug = Debug('cannon:cli');

/**
Expand Down Expand Up @@ -227,6 +228,15 @@ async function prepareBuildConfig(
) {
const { name, version, preset, def } = await loadCannonfile(cannonfile);

if (def.danglingDependencies.size) {
const neededDeps = Array.from(def.danglingDependencies).map((v) => v.split(':'));
throw new CannonError(
`Unknown template access found. Please ensure the following references are defined:\n${neededDeps
.map(([input, node]) => `${bold(input)} in ${italic(node)}`)
.join('\n')}`
);
}

const packageSpecification = {
name,
version,
Expand Down
12 changes: 11 additions & 1 deletion packages/hardhat-cannon/src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CANNON_CHAIN_ID, CannonSigner } from '@usecannon/builder';
import { build, createDryRunRegistry, loadCannonfile, parseSettings, resolveCliSettings } from '@usecannon/cli';
import { getChainById } from '@usecannon/cli/dist/src/chains';
import { getProvider } from '@usecannon/cli/dist/src/rpc';
import { bold, yellow, yellowBright } from 'chalk';
import { bold, italic, yellow, yellowBright } from 'chalk';
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names';
import { task } from 'hardhat/config';
import { HttpNetworkConfig } from 'hardhat/types';
Expand All @@ -14,6 +14,7 @@ import { loadPackageJson } from '../internal/load-pkg-json';
import { parseAnvilOptions } from '../internal/parse-anvil-options';
import { SubtaskRunAnvilNodeResult } from '../subtasks/run-anvil-node';
import { SUBTASK_GET_ARTIFACT, SUBTASK_RUN_ANVIL_NODE, TASK_BUILD } from '../task-names';
import { CannonError } from '@usecannon/builder';

task(TASK_BUILD, 'Assemble a defined chain and save it to to a state which can be used later')
.addPositionalParam('cannonfile', 'Path to a cannonfile to build', 'cannonfile.toml')
Expand Down Expand Up @@ -75,6 +76,15 @@ task(TASK_BUILD, 'Assemble a defined chain and save it to to a state which can b

const { name, version, def, preset } = await loadCannonfile(path.join(hre.config.paths.root, cannonfile));

if (def.danglingDependencies.size) {
const neededDeps = Array.from(def.danglingDependencies).map((v) => v.split(':'));
throw new CannonError(
`Unknown template access found. Please ensure the following references are defined:\n${neededDeps
.map(([input, node]) => `${bold(input)} in ${italic(node)}`)
.join('\n')}`
);
}

if (hre.network.name === 'hardhat' && dryRun) {
throw new Error('You cannot use --dry-run param when using the "hardhat" network');
}
Expand Down
17 changes: 17 additions & 0 deletions packages/website/src/features/Deploy/QueueFromGitOpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,22 @@ function QueueFromGitOps() {
);
}

if (cannonDefInfo.def && cannonDefInfo.def.danglingDependencies.size > 0) {
alertMessage = (
<>
The cannonfile contains invalid dependencies. Please ensure the
following references are defined:
{Array.from(cannonDefInfo.def.danglingDependencies).map(
([input, node]) => (
<Text key={`${input}:${node}`} as="span" fontFamily="monospace">
{input} in {node}
</Text>
)
)}
</>
);
}

return alertMessage ? (
<VStack mt="6" spacing={2} mb={6}>
<Alert status="error" bg="gray.700">
Expand All @@ -460,6 +476,7 @@ function QueueFromGitOps() {
const disablePreviewButton =
chainId !== currentSafe?.chainId ||
!cannonDefInfo.def ||
cannonDefInfo.def.danglingDependencies.size > 0 ||
cannonPkgPreviousInfo.isFetching ||
partialDeployInfo.isFetching ||
cannonPkgVersionInfo.isFetching ||
Expand Down
Loading