diff --git a/src/bin/thin_metadata_unpack.rs b/src/bin/thin_metadata_unpack.rs index 0664557..94874a3 100644 --- a/src/bin/thin_metadata_unpack.rs +++ b/src/bin/thin_metadata_unpack.rs @@ -39,7 +39,7 @@ fn main() { } if let Err(reason) = thinp::pack::toplevel::unpack(&input_file, &output_file) { - println!("Application error: {}", reason); + eprintln!("Application error: {}", reason); process::exit(1); } } diff --git a/src/pack/toplevel.rs b/src/pack/toplevel.rs index d4adf7d..2298cea 100644 --- a/src/pack/toplevel.rs +++ b/src/pack/toplevel.rs @@ -163,24 +163,28 @@ fn read_header(mut r: R) -> io::Result where R: byteorder::ReadBytesExt, { - use std::process::exit; - let magic = r.read_u64::()?; if magic != MAGIC { - eprintln!("Not a pack file."); - exit(1); + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "Not a pack file", + )); } let version = r.read_u64::()?; if version != PACK_VERSION { - eprintln!("unsupported pack file version ({}).", PACK_VERSION); - exit(1); + return Err(io::Error::new( + io::ErrorKind::InvalidData, + format!("unsupported pack file version ({}).", PACK_VERSION), + )); } let block_size = r.read_u64::()?; if block_size != BLOCK_SIZE { - eprintln!("block size is not {}", BLOCK_SIZE); - exit(1); + return Err(io::Error::new( + io::ErrorKind::InvalidData, + format!("block size is not {}", BLOCK_SIZE), + )); } r.read_u64::() @@ -270,6 +274,8 @@ pub fn unpack(input_file: &Path, output_file: &Path) -> Result<(), Box Result<(), Box