diff --git a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs
index b970c7d63063..818ba1a9afd7 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs
+++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs
@@ -1,5 +1,6 @@
use crate::utils::PACKAGE_NIX_FILENAME;
use crate::ErrorWriter;
+use itertools::concat;
use itertools::{Either, Itertools};
use rnix::parser::ParseError;
use std::ffi::OsString;
@@ -245,6 +246,17 @@ pub fn pass(value: A) -> CheckResult {
pub type CheckResult = anyhow::Result, A>>;
+pub fn sequence_check_results(first: CheckResult<()>, second: CheckResult) -> CheckResult {
+ match (first?, second?) {
+ (Either::Right(_), Either::Right(right_value)) => pass(right_value),
+ (Either::Left(errors), Either::Right(_)) => Ok(Either::Left(errors)),
+ (Either::Right(_), Either::Left(errors)) => Ok(Either::Left(errors)),
+ (Either::Left(errors_l), Either::Left(errors_r)) => {
+ Ok(Either::Left(concat([errors_l, errors_r])))
+ }
+ }
+}
+
pub fn flatten_check_results(
check_results: impl IntoIterator- >,
value_transform: impl Fn(Vec) -> O,
diff --git a/pkgs/test/nixpkgs-check-by-name/src/structure.rs b/pkgs/test/nixpkgs-check-by-name/src/structure.rs
index 2f225ecd2ec3..d1655dc2e3fe 100644
--- a/pkgs/test/nixpkgs-check-by-name/src/structure.rs
+++ b/pkgs/test/nixpkgs-check-by-name/src/structure.rs
@@ -1,4 +1,6 @@
-use crate::check_result::{flatten_check_results, pass, write_check_result, CheckError};
+use crate::check_result::{
+ flatten_check_results, pass, sequence_check_results, write_check_result, CheckError,
+};
use crate::utils;
use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME};
use lazy_static::lazy_static;
@@ -67,7 +69,7 @@ impl Nixpkgs {
// we can't check for any other errors if it's a file, since there's no subdirectories to check
} else {
let shard_name_valid = SHARD_NAME_REGEX.is_match(&shard_name);
- let shard_name_valid_check_result = if !shard_name_valid {
+ let check_result = if !shard_name_valid {
CheckError::InvalidShardName {
relative_shard_path: relative_shard_path.clone(),
shard_name: shard_name.clone(),
@@ -77,8 +79,6 @@ impl Nixpkgs {
pass(())
};
- write_check_result(error_writer, shard_name_valid_check_result)?;
-
let entries = utils::read_dir_sorted(&shard_path)?;
let duplicate_check_results = entries
@@ -96,10 +96,10 @@ impl Nixpkgs {
.into_result::<()>()
});
- let duplicate_check_result =
- flatten_check_results(duplicate_check_results, |_| ());
-
- write_check_result(error_writer, duplicate_check_result)?;
+ let check_result = sequence_check_results(
+ check_result,
+ flatten_check_results(duplicate_check_results, |_| ()),
+ );
let check_results = entries.into_iter().map(|package_entry| {
let package_path = package_entry.path();
@@ -170,7 +170,10 @@ impl Nixpkgs {
}
});
- flatten_check_results(check_results, |x| x)
+ sequence_check_results(
+ check_result,
+ flatten_check_results(check_results, |x| x),
+ )
}
});