Skip to content

Commit

Permalink
fix: exit with nonzero code on init cmd error (near#8334)
Browse files Browse the repository at this point in the history
near#5967 refactored things so that the init command wouldn't panic on normal/expected errors, but it inadvertenly changed things so that we always get exit code 0 even when the command fails, which is quite sad. So just return an `anyhow::Error` from `InitCmd::run()`
  • Loading branch information
marcelo-gonzalez authored and nikurt committed Jan 15, 2023
1 parent fe4c0a8 commit 9aeab12
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions neard/src/cli.rs
Expand Up @@ -83,7 +83,7 @@ impl NeardCmd {
};

match neard_cmd.subcmd {
NeardSubCommand::Init(cmd) => cmd.run(&home_dir),
NeardSubCommand::Init(cmd) => cmd.run(&home_dir)?,
NeardSubCommand::Localnet(cmd) => cmd.run(&home_dir),
NeardSubCommand::Run(cmd) => cmd.run(
&home_dir,
Expand Down Expand Up @@ -312,17 +312,16 @@ fn check_release_build(chain: &str) {
}

impl InitCmd {
pub(super) fn run(self, home_dir: &Path) {
pub(super) fn run(self, home_dir: &Path) -> anyhow::Result<()> {
// TODO: Check if `home` exists. If exists check what networks we already have there.
if (self.download_genesis || self.download_genesis_url.is_some()) && self.genesis.is_some()
{
error!("Please give either --genesis or --download-genesis, not both.");
return;
anyhow::bail!("Please give either --genesis or --download-genesis, not both.");
}

self.chain_id.as_ref().map(|chain| check_release_build(chain));

if let Err(e) = nearcore::init_configs(
nearcore::init_configs(
home_dir,
self.chain_id.as_deref(),
self.account_id.and_then(|account_id| account_id.parse().ok()),
Expand All @@ -337,9 +336,8 @@ impl InitCmd {
self.download_config_url.as_deref(),
self.boot_nodes.as_deref(),
self.max_gas_burnt_view,
) {
error!("Failed to initialize configs: {:#}", e);
}
)
.context("Failed to initialize configs")
}
}

Expand Down

0 comments on commit 9aeab12

Please sign in to comment.