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

Descriptive error instead of allowing starting a node with forc run #786

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised rustfmt doesn't try and wrap this or break the format! args onto different lines, but if rustfmt's happy I'm happy!

Self { message }
}
}

impl fmt::Display for CliError {
Expand Down