From 61370130c32f68a8e85d27c3366482c161d50bf0 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Wed, 19 Feb 2025 12:15:25 +0000 Subject: [PATCH 1/8] start work --- crates/tuono/src/app.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index 86db505c..f278bf43 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -208,18 +208,21 @@ 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) => { + eprintln!("[CLI] Failed to read tuono.config.ts with the following error:"); + eprintln!("{}", error); + std::process::exit(1); + } + } config_build_command } From c91a58e37dc8558e10a7d9a5cc585b4ebf9919e6 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Wed, 19 Feb 2025 13:56:53 +0000 Subject: [PATCH 2/8] fix tests (squashed) --- crates/tuono/tests/cli_build.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index 92e4a70d..d66796eb 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -168,11 +168,19 @@ fn it_fails_without_installed_build_script() { .assert() .success(); let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); + #[cfg(target_os = "windows")] test_tuono_build .arg("build") .assert() .failure() - .stderr("[CLI] Failed to read tuono.config.ts\n"); + .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nThe system cannot find the path specified (os error 3)\n"); + + #[cfg(not(target_os = "windows"))] + test_tuono_build + .arg("build") + .assert() + .failure() + .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nNo such file or directory (os error 2)\n"); } #[test] From 91b24ec1e9c8fba0bbab5671ca263f7bd3fd308e Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Thu, 20 Feb 2025 10:26:48 +0000 Subject: [PATCH 3/8] add full stop for windows (painful) --- crates/tuono/tests/cli_build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index d66796eb..e2a10b22 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -173,7 +173,7 @@ fn it_fails_without_installed_build_script() { .arg("build") .assert() .failure() - .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nThe system cannot find the path specified (os error 3)\n"); + .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nThe system cannot find the path specified. (os error 3)\n"); #[cfg(not(target_os = "windows"))] test_tuono_build From 6a88ca3a5d04a871a2660fab320d6365b87bd80e Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Fri, 21 Feb 2025 10:41:13 +0000 Subject: [PATCH 4/8] give error hint --- crates/tuono/src/app.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index f278bf43..f8a5a81b 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -5,8 +5,9 @@ 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::io::{BufReader, Error}; use std::path::Path; use std::path::PathBuf; use std::process::Child; @@ -218,8 +219,13 @@ impl App { match Config::get() { Ok(config) => self.config = Some(config), Err(error) => { - eprintln!("[CLI] Failed to read tuono.config.ts with the following error:"); - eprintln!("{}", error); + match error.kind() { + io::ErrorKind::NotFound => eprintln!("[CLI] Failed to read config. Please run `npm install` to generate automatically."), + _ => { + eprintln!("[CLI] Failed to read tuono.config.ts with the following error:"); + eprintln!("{}", error); + } + } std::process::exit(1); } } From 75347b0659462c973fcc4a6fdcaa10ffb99cc323 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Fri, 21 Feb 2025 14:22:00 +0000 Subject: [PATCH 5/8] suggestions --- crates/tuono/src/app.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index f8a5a81b..1ff501d1 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -7,7 +7,7 @@ use std::collections::{hash_map::Entry, HashMap}; use std::fs::File; use std::io; use std::io::prelude::*; -use std::io::{BufReader, Error}; +use std::io::BufReader; use std::path::Path; use std::path::PathBuf; use std::process::Child; @@ -222,8 +222,8 @@ impl App { match error.kind() { io::ErrorKind::NotFound => eprintln!("[CLI] Failed to read config. Please run `npm install` to generate automatically."), _ => { - eprintln!("[CLI] Failed to read tuono.config.ts with the following error:"); - eprintln!("{}", error); + error!("[CLI] Failed to read config with the following error:"); + error!("{}", error); } } std::process::exit(1); From e54a04b83b01e291f11e3666022b17ed8533fbc9 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Fri, 21 Feb 2025 14:25:40 +0000 Subject: [PATCH 6/8] update tests --- crates/tuono/tests/cli_build.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index e2a10b22..3a4457d9 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -168,19 +168,10 @@ fn it_fails_without_installed_build_script() { .assert() .success(); let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); - #[cfg(target_os = "windows")] - test_tuono_build - .arg("build") - .assert() - .failure() - .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nThe system cannot find the path specified. (os error 3)\n"); - #[cfg(not(target_os = "windows"))] - test_tuono_build - .arg("build") - .assert() - .failure() - .stderr("[CLI] Failed to read tuono.config.ts with the following error:\nNo such file or directory (os error 2)\n"); + test_tuono_build.arg("build").assert().failure().stderr( + "[CLI] Failed to read config. Please run `npm install` to generate automatically.\n", + ); } #[test] From cac58ac035d6ee3ffe14dc40ff466b119931df29 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Sun, 23 Feb 2025 10:49:29 +0000 Subject: [PATCH 7/8] suggestions --- crates/tuono/src/app.rs | 4 ++-- crates/tuono/tests/cli_build.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/tuono/src/app.rs b/crates/tuono/src/app.rs index 1ff501d1..f3e58087 100644 --- a/crates/tuono/src/app.rs +++ b/crates/tuono/src/app.rs @@ -220,9 +220,9 @@ impl App { Ok(config) => self.config = Some(config), Err(error) => { match error.kind() { - io::ErrorKind::NotFound => eprintln!("[CLI] Failed to read config. Please run `npm install` to generate automatically."), + io::ErrorKind::NotFound => eprintln!("Failed to read config. Please run `npm install` to generate automatically."), _ => { - error!("[CLI] Failed to read config with the following error:"); + error!("Failed to read config with the following error:"); error!("{}", error); } } diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index 63fb4e78..17b45ca9 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -169,7 +169,7 @@ fn it_fails_without_installed_build_script() { let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); test_tuono_build.arg("build").assert().failure().stderr( - "[CLI] Failed to read config. Please run `npm install` to generate automatically.\n", + "Failed to read config. Please run `npm install` to generate automatically.\n", ); } From 0f0c3f4facd934dd69ed74efc225addb03910e9a Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Sun, 23 Feb 2025 10:51:08 +0000 Subject: [PATCH 8/8] lint --- crates/tuono/tests/cli_build.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/tuono/tests/cli_build.rs b/crates/tuono/tests/cli_build.rs index 17b45ca9..f87a7001 100644 --- a/crates/tuono/tests/cli_build.rs +++ b/crates/tuono/tests/cli_build.rs @@ -168,9 +168,11 @@ fn it_fails_without_installed_build_script() { .success(); let mut test_tuono_build = Command::cargo_bin("tuono").unwrap(); - test_tuono_build.arg("build").assert().failure().stderr( - "Failed to read config. Please run `npm install` to generate automatically.\n", - ); + test_tuono_build + .arg("build") + .assert() + .failure() + .stderr("Failed to read config. Please run `npm install` to generate automatically.\n"); } #[test]