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

fix(cli): check rpc url and chain id before throwing an error #1533

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all 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
13 changes: 6 additions & 7 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getMainLoader } from './loader';
import { installPlugin, listInstalledPlugins, removePlugin } from './plugins';
import { createDefaultReadRegistry } from './registry';
import { CannonRpcNode, getProvider, runRpc } from './rpc';
import { resolveCliSettings } from './settings';
import { DEFAULT_RPC_URL, resolveCliSettings } from './settings';
import { PackageSpecification } from './types';

import { doBuild } from './util/build';
Expand Down Expand Up @@ -160,12 +160,6 @@ applyCommandsConfig(program.command('build'), commandsConfig.build)
// ensure foundry compatibility
await ensureFoundryCompatibility();

// throw an error if chain id is undefined and dry run is true
// chain id undefined means the user wants to use Cannon Network
if (options.chainId === undefined && options.dryRun) {
throw new Error('Cannot build on Cannon Network with --dry-run flag.');
}

// backwards compatibility for --port flag
if (options.port !== ANVIL_PORT_DEFAULT_VALUE) {
deprecatedWarn('--port', '--anvil.port');
Expand All @@ -179,6 +173,11 @@ applyCommandsConfig(program.command('build'), commandsConfig.build)

const cliSettings = resolveCliSettings(options);

// throw an error if chain id and rpc url is undefined and dry run is true
if (options.chainId === undefined && cliSettings.rpcUrl === DEFAULT_RPC_URL && options.dryRun) {
throw new Error('Cannot build on Cannon Network with --dry-run flag.');
}

// throw an error if the chainId is not consistent with the provider's chainId
await ensureChainIdConsistency(cliSettings.rpcUrl, options.chainId);

Expand Down
Loading