Skip to content

Commit

Permalink
Give descriptive error instead of allowing starting a node with forc …
Browse files Browse the repository at this point in the history
…run. (FuelLabs#786)
  • Loading branch information
adlerjohn authored Feb 14, 2022
1 parent 1631570 commit afd03c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
21 changes: 2 additions & 19 deletions forc/src/ops/forc_run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fuel_gql_client::client::FuelClient;
use fuel_tx::Transaction;
use futures::TryFutureExt;
use std::io::{self, Write};

use std::path::PathBuf;
use std::str::FromStr;
use sway_core::{parse, TreeType};
Expand All @@ -10,7 +10,6 @@ use tokio::process::Child;
use crate::cli::{BuildCommand, RunCommand};
use crate::ops::forc_build;
use crate::utils::cli_error::CliError;
use crate::utils::client::start_fuel_core;

use crate::utils::helpers;
use helpers::{get_main_file, read_manifest};
Expand Down Expand Up @@ -116,23 +115,7 @@ async fn try_send_tx(
send_tx(&client, tx, pretty_print).await?;
Ok(None)
}
Err(_) => {
print!(
"We noticed you don't have fuel-core running, would you like to start a node [y/n]?"
);
io::stdout().flush().unwrap();
let mut reply = String::new();
io::stdin().read_line(&mut reply)?;
let reply = reply.trim().to_lowercase();

if reply == "y" || reply == "yes" {
let child = start_fuel_core(node_url, &client).await?;
send_tx(&client, tx, pretty_print).await?;
Ok(Some(child))
} else {
Ok(None)
}
}
Err(_) => Err(CliError::fuel_core_not_running(node_url)),
}
}

Expand Down
5 changes: 5 additions & 0 deletions forc/src/utils/cli_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ impl CliError {
);
Self { message }
}

pub fn fuel_core_not_running(node_url: &str) -> Self {
let message = format!("could not get a response from node at the URL {}. Start a node with `fuel-core`. See <https://github.com/FuelLabs/fuel-core#running> for more information", node_url);
Self { message }
}
}

impl fmt::Display for CliError {
Expand Down

0 comments on commit afd03c8

Please sign in to comment.