Skip to content

Commit

Permalink
🚧(main): opt error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
W-Mai committed Mar 6, 2024
1 parent 9e15ac4 commit 3128116
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion icu_lib/src/midata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::endecoder;
use crate::endecoder::EnDecoder;
use crate::EncoderParams;
use image::{GrayAlphaImage, RgbaImage};
Expand Down
29 changes: 13 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ fn get_info_with(
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() {
let res = process();

if let Err(e) = res {
log::error!("{}", e);
std::process::exit(1);
}
}

fn process() -> Result<(), Box<dyn std::error::Error>> {
let args = parse_args();

env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
Expand All @@ -57,25 +66,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

match &commands {
SubCommands::Info { file, input_format } => {
// check file exists
if fs::metadata(file).is_err() {
log::error!("File not found: {}", file);
return Err(format!("File not found: {}", file).into());
}

let data = fs::read(file).expect("Unable to read file");
let data = fs::read(file)?;
let info = get_info_with(data, *input_format)?;

println!("{:#?}", info);
}
SubCommands::Show { file, input_format } => {
// check file exists
if fs::metadata(file).is_err() {
log::error!("File not found: {}", file);
return Err(format!("File not found: {}", file).into());
}

let data = fs::read(file).expect("Unable to read file");
let data = fs::read(file)?;
let mid = decode_with(data, *input_format);

show_image(mid?);
Expand Down Expand Up @@ -189,7 +186,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fs::write(&output_file_path, data).expect("Unable to write file");
}
OutputFileFormatCategory::C_Array => {
panic!("C_Array output format is not supported yet");
return Err("C_Array output format is not supported yet".into());
}
}
}
Expand Down

0 comments on commit 3128116

Please sign in to comment.