From 6727264e3966bf4a9b5fb0cc52cb56c7404181c3 Mon Sep 17 00:00:00 2001 From: "Myan V." <155415707+myanvoos@users.noreply.github.com> Date: Sat, 23 Nov 2024 01:38:54 +1300 Subject: [PATCH] Better error handling when trying to overwrite an existing folder and using a non-existent template (#135) * fix: prevent overwriting existing project directories * refactor: improve scaffold error messages --- crates/tuono/src/scaffold_project.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/tuono/src/scaffold_project.rs b/crates/tuono/src/scaffold_project.rs index e4bce0a4..6ea5021c 100644 --- a/crates/tuono/src/scaffold_project.rs +++ b/crates/tuono/src/scaffold_project.rs @@ -63,11 +63,17 @@ pub fn create_new_project(folder_name: Option, template: Option) .collect::>(); if new_project_files.is_empty() { - println!("Template not found: {template}"); - return; + eprintln!("Error: Template '{template}' not found"); + println!("Hint: you can view the available templates at https://github.com/Valerioageno/tuono/tree/main/examples"); + std::process::exit(1); } if folder != "." { + if Path::new(&folder).exists() { + eprintln!("Error: Directory '{folder}' already exists"); + println!("Hint: you can scaffold a tuono project within an existing folder with 'cd {folder} && tuono new .'"); + std::process::exit(1); + } create_dir(&folder).unwrap(); }