From 294c9de3aef411cc7bafb4d532c808e79e76b756 Mon Sep 17 00:00:00 2001 From: Ulrich Hornung Date: Sat, 2 Mar 2024 13:23:16 +0100 Subject: [PATCH] extend error message for case when writer instanciation fails second time --- src/uu/split/src/split.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index ed952e7a1..c8ca83ae5 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -1225,11 +1225,20 @@ impl ManageOutFiles for OutFiles { } // And then try to instantiate the writer again // If this fails - give up and propagate the error - self[idx].maybe_writer = - Some(settings.instantiate_current_writer( - self[idx].filename.as_str(), - self[idx].is_new, - )?); + let result = settings + .instantiate_current_writer(self[idx].filename.as_str(), self[idx].is_new); + if let Err(e) = result { + let mut count = 0; + for out_file in self { + if out_file.maybe_writer.is_some() { + count += 1; + } + } + + return Err(USimpleError::new(e.raw_os_error().unwrap_or(1), + format!("Instantiation of writer failed due to error: {e:?}. Existing writer number: {count}"))); + } + self[idx].maybe_writer = Some(result?); Ok(self[idx].maybe_writer.as_mut().unwrap()) } }