From ffcddb0b2b85868c96e567f6eccde95b5003e9d6 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Fri, 4 Aug 2023 16:22:23 -0400 Subject: [PATCH] Improve error output --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 5 ++++- src/ndjson_log.rs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e2c824..a90f4b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -923,7 +923,7 @@ dependencies = [ [[package]] name = "rx-repack" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "camino", diff --git a/Cargo.toml b/Cargo.toml index 05f542a..3d718b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rx-repack" description = "Rust re-write of px-repack" -version = "0.4.0" +version = "0.4.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index fbf7c5c..ed8c2e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use camino::Utf8PathBuf; use clap::Parser; use rx_repack::{json_message, repack}; @@ -65,5 +66,7 @@ fn main() -> anyhow::Result<()> { println!("{}", json_message(&dicom_file, &outcome)?); } - outcome.map(|_| ()) + outcome + .with_context(|| format!("Failed to pack: {}", &dicom_file)) + .map(|_| ()) } diff --git a/src/ndjson_log.rs b/src/ndjson_log.rs index d884a09..6652407 100644 --- a/src/ndjson_log.rs +++ b/src/ndjson_log.rs @@ -8,9 +8,9 @@ use std::os::unix::fs::MetadataExt; pub fn json_message( src: &Utf8Path, result: &anyhow::Result, -) -> anyhow::Result { +) -> serde_json::Result { let msg = Message::new(src, result); - serde_json::to_string(&msg).map_err(anyhow::Error::from) + serde_json::to_string(&msg) } #[allow(non_snake_case)]