From de5ac53cc3cf931b1597c48df557da837f5ac921 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Sun, 23 Feb 2025 11:15:12 +0000 Subject: [PATCH] feat: more detailed errors for `Failed to read tuono.config.ts` (#579) --- crates/tuono/src/app.rs | 21 +++++++++++++++------ crates/tuono/tests/cli_build.rs | 3 ++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index 86db505c..f3e58087 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -5,6 +5,7 @@ use http::Method; use std::collections::hash_set::HashSet; use std::collections::{hash_map::Entry, HashMap}; use std::fs::File; +use std::io; use std::io::prelude::*; use std::io::BufReader; use std::path::Path; @@ -208,18 +209,26 @@ impl App { eprintln!("Failed to find the build script. Please run `npm install`"); std::process::exit(1); } + let config_build_command = Command::new(BUILD_TUONO_CONFIG) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output(); - if let Ok(config) = Config::get() { - self.config = Some(config); - } else { - eprintln!("[CLI] Failed to read tuono.config.ts"); - std::process::exit(1); - }; + match Config::get() { + Ok(config) => self.config = Some(config), + Err(error) => { + match error.kind() { + io::ErrorKind::NotFound => eprintln!("Failed to read config. Please run `npm install` to generate automatically."), + _ => { + error!("Failed to read config with the following error:"); + error!("{}", error); + } + } + std::process::exit(1); + } + } config_build_command } diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index c807e471..f87a7001 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -167,11 +167,12 @@ fn it_fails_without_installed_build_script() { .assert() .success(); let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); + test_tuono_build .arg("build") .assert() .failure() - .stderr("[CLI] Failed to read tuono.config.ts\n"); + .stderr("Failed to read config. Please run `npm install` to generate automatically.\n"); } #[test]