Skip to content

Commit 64ff118

Browse files
committed
refactor: improve save file error handling
- add error and info to tracing imports - refactor save logic to use match for better error handling - remove direct stdout message on save success Signed-off-by: mingcheng <[email protected]>
1 parent 5e1ceed commit 64ff118

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use clap::Parser;
2626
use std::error::Error;
2727
use std::fs;
2828
use std::io::Write;
29-
use tracing::{Level, debug, trace};
29+
use tracing::{Level, debug, error, info, trace};
3030

3131
use aigitcommit::utils::{
3232
OutputFormat, check_env_variables, format_openai_error, get_env, save_to_file, should_signoff,
@@ -185,10 +185,16 @@ async fn main() -> std::result::Result<(), Box<dyn Error>> {
185185
// If the --save option is enabled, save the commit message to a file
186186
if !cli.save.is_empty() {
187187
trace!("save option is enabled, will save the commit message to a file");
188-
debug!("the save file path is {:?}", &cli.save);
189188

190-
save_to_file(&cli.save, &message)?;
191-
writeln!(std::io::stdout(), "commit message saved to {}", cli.save)?;
189+
// Save the commit message to the specified file
190+
match save_to_file(&cli.save, &message) {
191+
Ok(f) => {
192+
info!("commit message saved to file: {:?}", f);
193+
}
194+
Err(e) => {
195+
error!("failed to save commit message to file: {}", e);
196+
}
197+
}
192198
}
193199

194200
Ok(())

0 commit comments

Comments
 (0)