Skip to content

Commit e26989a

Browse files
committed
Use with_subitem on zip_reads errors
1 parent a5640b4 commit e26989a

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

‎crates/irma-records/paired/zip_reads.rs‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88
use zoe::{
99
data::{
10-
err::{GetCode, WithErrorContext},
10+
err::{ErrorWithContext, GetCode, WithErrorContext, WithSubitem},
1111
records::HeaderReadable,
1212
},
1313
unwrap_or_return_some_err,
@@ -89,13 +89,15 @@ where
8989
ZipPairedReadsError::BadHeaders {
9090
records: [r1, r2],
9191
source,
92-
} => source.with_context(format!(
93-
"Did not find corresponding paired reads in {path1} and {path2}.\n | Header 1: {header1}\n | Header 2: {header2}",
94-
path1 = path1.display(),
95-
path2 = path2.display(),
96-
header1 = r1.header(),
97-
header2 = r2.header(),
98-
)).into(),
92+
} => source
93+
.with_context(format!(
94+
"Did not find corresponding paired reads in {path1} and {path2}",
95+
path1 = path1.display(),
96+
path2 = path2.display(),
97+
))
98+
.with_subitem(format!("Header 1: {header1}", header1 = r1.header()))
99+
.with_subitem(format!("Header 2: {header2}", header2 = r2.header()))
100+
.into(),
99101
ZipPairedReadsError::ExtraFirstRead(r1) => {
100102
std::io::Error::other(format!("Unexpected read found with header: {header1}", header1 = r1.header()))
101103
.with_path_context("An extra read was found in file", path1)
@@ -259,12 +261,13 @@ impl<A: HeaderReadable> Display for ZipPairedReadsError<A> {
259261
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260262
match self {
261263
ZipPairedReadsError::IoError(e) => write!(f, "{e}"),
262-
ZipPairedReadsError::BadHeaders { records: [r1, r2], .. } => write!(
263-
f,
264-
"Paired read IDs out of sync:\n | Header 1: {h1}\n | Header 2: {h2}",
265-
h1 = r1.header(),
266-
h2 = r2.header()
267-
),
264+
ZipPairedReadsError::BadHeaders { records: [r1, r2], .. } => {
265+
let err = ErrorWithContext::new("Paired read IDs out of sync:")
266+
.with_subitem(format!("Header 1: {h1}", h1 = r1.header()))
267+
.with_subitem(format!("Header 2: {h2}", h2 = r2.header()));
268+
269+
write!(f, "{err}",)
270+
}
268271
ZipPairedReadsError::ExtraFirstRead(r1) => write!(
269272
f,
270273
"An extra read in the first file was found with header {header1}",

0 commit comments

Comments
 (0)