diff --git a/subgraph/cli/deploy/mod.rs b/subgraph/cli/deploy/mod.rs index a8113ec25..e7c5c4f0b 100644 --- a/subgraph/cli/deploy/mod.rs +++ b/subgraph/cli/deploy/mod.rs @@ -36,6 +36,10 @@ pub struct DeployArgs { } pub fn deploy_subgraph(config: DeployArgs) -> anyhow::Result<()> { + if config.url.scheme() != "http" && config.url.scheme() != "https" { + return Err(anyhow!("Invalid URL provided")); + } + let subgraph_template = "subgraph.template.yaml"; let output_path = "subgraph.yaml"; diff --git a/subgraph/cli/main.rs b/subgraph/cli/main.rs index d6c44acc7..05bf7e528 100644 --- a/subgraph/cli/main.rs +++ b/subgraph/cli/main.rs @@ -3,7 +3,7 @@ mod deploy; mod utils; use clap::{Parser, Subcommand}; -// use colored::*; +use colored::*; use deploy::{deploy_subgraph, DeployArgs}; use utils::run_cmd; @@ -31,34 +31,52 @@ fn main() -> Result<(), anyhow::Error> { match args.subgraph { Subgraph::Install => { - run_cmd("npm", &["install"]); + let resp = run_cmd("npm", &["install"]); + + if !resp { + eprintln!("{}", "Error: Failed at npm install".red()); + std::process::exit(1); + } Ok(()) } Subgraph::Build => { - run_cmd("npm", &["run", "codegen"]); - run_cmd("npm", &["run", "build"]); + let resp = run_cmd("npm", &["run", "codegen"]); + if !resp { + eprintln!("{}", "Error: Failed at npm run codegen".red()); + std::process::exit(1); + } + + let resp = run_cmd("npm", &["run", "build"]); + if !resp { + eprintln!("{}", "Error: Failed at npm run build".red()); + std::process::exit(1); + } Ok(()) } Subgraph::Test => { - run_cmd("nix", &["run", ".#ci-test"]); + let resp = run_cmd("nix", &["run", ".#ci-test"]); + if !resp { + std::process::exit(1); + } Ok(()) } - Subgraph::Deploy(args) => { - println!("\nšŸš€ Hello deploy"); - let _ = deploy_subgraph(args); - - // if args.url.scheme() != "http" && args.url.scheme() != "https" { - // eprintln!("Error: Invalid URL provided"); - // std::process::exit(1); - // } - - Ok(()) + Subgraph::Deploy(args) => { + match deploy_subgraph(args) { + Ok(_) => { + return Ok(()); + } + Err(err) => { + // Error occurred, print the error message and exit + eprintln!("Error: {}", err); + std::process::exit(1); + } + } } } } diff --git a/subgraph/cli/utils/mod.rs b/subgraph/cli/utils/mod.rs index f06e0977b..d41c871be 100644 --- a/subgraph/cli/utils/mod.rs +++ b/subgraph/cli/utils/mod.rs @@ -8,7 +8,6 @@ use std::thread; pub fn run_cmd(main_cmd: &str, args: &[&str]) -> bool { // Get the current working directory let current_dir = env::current_dir().expect("Failed to get current directory"); - println!("current_dir: {:?}", current_dir.to_str()); // Create a new Command to run let mut cmd = Command::new(main_cmd); diff --git a/subgraph/flake.nix b/subgraph/flake.nix index a855b21fe..f2d285059 100644 --- a/subgraph/flake.nix +++ b/subgraph/flake.nix @@ -87,6 +87,11 @@ # This in case the subgraph schema.graphql have changes when running tests ${gen-sg-schema} + echo "Print root" + ls . + echo "Print query folder" + ls tests/subgraph/query + # Run tests in single thread cargo test -- --test-threads=1 --nocapture; '');