slightly better error handling in main

main
nick 2024-10-05 20:57:44 -04:00
parent 5d62329e42
commit f4a3a46c71
1 changed files with 11 additions and 5 deletions

View File

@ -14,7 +14,7 @@ use terminal::Terminal;
use pane::prelude::*;
use std::fs::{remove_file, OpenOptions};
use std::io::Error;
use std::io::{Error, ErrorKind};
use anyhow::{Result as AnyResult, Error as AnyError};
use clap::Parser;
@ -32,16 +32,22 @@ fn main() -> AnyResult<()> {
.create_new(true)
.open(LOG_FILE)
.map_err(|e| {
<Error as Into<AnyError>>::into(e).context(LOG_FILE).context(LOG_EXISTS_MSG)
let kind = e.kind();
let result = AnyError::from(e).context(LOG_FILE);
if kind == ErrorKind::AlreadyExists {
result.context(LOG_EXISTS_MSG)
} else {
result
}
})?;
let _redirect = Redirect::stderr(target)?;
do_tui(args)?;
let result = do_tui(args);
remove_file(LOG_FILE)?;
Ok(())
result.map_err(Into::into)
}
fn do_tui(args: Args) -> Result<(), Error> {