From c763b3e664115823451d01f3cdb7004f480ca996 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 29 Sep 2026 16:03:11 +0200 Subject: [PATCH] fix: identify failed input documents --- src/bin/john-slop.rs | 5 ++++- src/error.rs | 19 +++++++++++++++++++ tests/cli.rs | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/bin/john-slop.rs b/src/bin/john-slop.rs index d43b851..29878f8 100644 --- a/src/bin/john-slop.rs +++ b/src/bin/john-slop.rs @@ -223,7 +223,10 @@ fn run(cli: &Cli) -> Result { let document = match document { Ok(document) => document, Err(error) => { - emit_input_error(cli.output, &path.display().to_string(), &error.to_string())?; + let source = error + .source_id() + .map_or_else(|| path.display().to_string(), ToString::to_string); + emit_input_error(cli.output, &source, &error.to_string())?; outcome.input_errors = true; continue; } diff --git a/src/error.rs b/src/error.rs index 3a35585..f4bd197 100644 --- a/src/error.rs +++ b/src/error.rs @@ -109,5 +109,24 @@ pub enum InputError { }, } +impl InputError { + /// Return the exact document identity when the failure occurred after discovery. + pub const fn source_id(&self) -> Option<&SourceId> { + match self { + Self::LimitExceeded { source_id, .. } + | Self::CompressionRatio { source_id, .. } + | Self::EncryptedMember { source_id } + | Self::BinaryContent { source_id } + | Self::InvalidUtf8 { source_id, .. } => Some(source_id), + Self::StdinIo { .. } + | Self::MissingPath { .. } + | Self::Io { .. } + | Self::Walk { .. } + | Self::Zip { .. } + | Self::UnsafeArchiveMember { .. } => None, + } + } +} + /// Result type used by the input layer. pub type InputResult = Result; diff --git a/tests/cli.rs b/tests/cli.rs index 48a090d..b07cc26 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -139,7 +139,11 @@ fn per_document_errors_preserve_other_json_results_and_force_exit_two() { assert!(output.stderr.is_empty()); let records = json_records(&output); assert_eq!(records.len(), 2); - assert!(records.iter().any(|record| record["kind"] == "input-error")); + let error = records + .iter() + .find(|record| record["kind"] == "input-error") + .unwrap(); + assert!(error["source"].as_str().unwrap().ends_with("a-invalid.txt")); assert!(records.iter().any(|record| record["kind"] == "analysis")); }