From 035c150f4cc9aa271c2cf2a4b380970bfa8454e0 Mon Sep 17 00:00:00 2001 From: Sebastian Kuzminsky Date: Mon, 7 Jul 2025 16:14:42 -0600 Subject: [PATCH] ent: better error reporting --- src/bin/ent/main.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/bin/ent/main.rs b/src/bin/ent/main.rs index 83ebb7f..9c31c60 100644 --- a/src/bin/ent/main.rs +++ b/src/bin/ent/main.rs @@ -35,7 +35,10 @@ enum Commands { Show { issue_id: String }, /// Modify the state of an issue - State { issue_id: String, new_state: Option }, + State { + issue_id: String, + new_state: Option, + }, } fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> { @@ -47,6 +50,7 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("{} {} ({:?})", uuid, issue.title(), issue.state); } } + Commands::New { description: Some(description), } => { @@ -54,11 +58,13 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( issue.set_description(description)?; println!("created new issue '{}'", issue.title()); } + Commands::New { description: None } => { let mut issue = entomologist::issue::Issue::new(issues_dir)?; issue.edit_description()?; println!("created new issue '{}'", issue.title()); } + Commands::Edit { issue_id } => { let mut issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; @@ -67,10 +73,11 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( issue.edit_description()?; } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } } + Commands::Show { issue_id } => { let issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; @@ -85,17 +92,20 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("{}", issue.description); } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } } - Commands::State { issue_id, new_state } => { + + Commands::State { + issue_id, + new_state, + } => { let mut issues = entomologist::issues::Issues::new_from_dir(std::path::Path::new(issues_dir))?; match issues.issues.get_mut(issue_id) { Some(issue) => { - let current_state = issue.state.clone(); - + let current_state = issue.state.clone(); match new_state { Some(s) => { issue.set_state(s.clone())?; @@ -107,10 +117,9 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<( println!("state: {}", current_state); } } - } None => { - println!("issue {} not found", issue_id); + return Err(anyhow::anyhow!("issue {} not found", issue_id)); } } }