fix: identify failed input documents
This commit is contained in:
parent
f3e53b1913
commit
c763b3e664
|
|
@ -223,7 +223,10 @@ fn run(cli: &Cli) -> Result<RunOutcome> {
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
19
src/error.rs
19
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<T> = Result<T, InputError>;
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue