diff --git a/xtask/src/build_docker_image.rs b/xtask/src/build_docker_image.rs index 1591e6aba..cf22e3cee 100644 --- a/xtask/src/build_docker_image.rs +++ b/xtask/src/build_docker_image.rs @@ -342,10 +342,10 @@ pub fn build_docker_image( } if results.iter().any(|r| r.is_err()) { #[allow(unknown_lints, clippy::manual_try_fold)] - results - .into_iter() - .filter_map(Result::err) - .fold(Err(eyre::eyre!("encountered error(s)")), |_, e| Err(e.1))?; + return Err(crate::util::with_section_reports( + eyre::eyre!("some error(s) encountered"), + results.into_iter().filter_map(Result::err).map(|e| e.1), + )); } Ok(()) } diff --git a/xtask/src/changelog.rs b/xtask/src/changelog.rs index ea4bc3277..1b4652fe9 100644 --- a/xtask/src/changelog.rs +++ b/xtask/src/changelog.rs @@ -5,9 +5,10 @@ use std::fs; use std::path::Path; use crate::util::{project_dir, write_to_string}; +use cross::shell::MessageInfo; + use chrono::{Datelike, Utc}; use clap::{Args, Subcommand}; -use cross::shell::MessageInfo; use cross::ToUtf8; use eyre::Context; use serde::Deserialize; @@ -508,6 +509,7 @@ pub fn build_changelog( Ok(()) } +#[allow(clippy::disallowed_methods)] pub fn validate_changelog( ValidateChangelog { mut files, .. }: ValidateChangelog, msg_info: &mut MessageInfo, @@ -532,19 +534,46 @@ pub fn validate_changelog( }) .collect(); } + let mut errors = vec![]; for file in files { let file_name = Path::new(&file); let path = changes_dir.join(file_name); let stem = file_stem(&path)?; - let contents = - fs::read_to_string(&path).wrap_err_with(|| eyre::eyre!("cannot find file {file}"))?; - let id = IdType::parse_stem(stem)?; - let value = serde_json::from_str(&contents) - .wrap_err_with(|| format!("unable to parse JSON for \"{file}\""))?; - let _ = ChangelogEntry::from_value(id, value) - .wrap_err_with(|| format!("unable to extract changelog from \"{file}\""))?; + let contents = fs::read_to_string(&path) + .wrap_err_with(|| eyre::eyre!("cannot find file {}", path.display()))?; + + let id = match IdType::parse_stem(stem) + .wrap_err_with(|| format!("unable to parse file stem for \"{}\"", path.display())) + { + Ok(id) => id, + Err(e) => { + errors.push(e); + continue; + } + }; + + let value = match serde_json::from_str(&contents) + .wrap_err_with(|| format!("unable to parse JSON for \"{}\"", path.display())) + { + Ok(value) => value, + Err(e) => { + errors.push(e); + continue; + } + }; + + let res = ChangelogEntry::from_value(id, value) + .wrap_err_with(|| format!("unable to extract changelog from \"{}\"", path.display())) + .map(|_| ()); + errors.extend(res.err()); } + if !errors.is_empty() { + return Err(crate::util::with_section_reports( + eyre::eyre!("some files were not validated"), + errors, + )); + } // also need to validate the existing changelog let _ = read_changelog(&root)?; diff --git a/xtask/src/util.rs b/xtask/src/util.rs index 146b457e7..bbadba779 100644 --- a/xtask/src/util.rs +++ b/xtask/src/util.rs @@ -1,8 +1,8 @@ -use std::env; use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Command; +use std::{env, fmt::Write as _}; use cross::shell::MessageInfo; use cross::{docker, CommandExt, ToUtf8}; @@ -118,6 +118,16 @@ pub fn get_matrix() -> &'static Vec { .unwrap() } +pub fn with_section_reports( + origin: eyre::Report, + iter: impl IntoIterator, +) -> eyre::Report { + use color_eyre::{Section as _, SectionExt as _}; + iter.into_iter().fold(origin, |report, e| { + report.section(format!("{e:?}").header("Error:")) + }) +} + pub fn format_repo(registry: &str, repository: &str) -> String { let mut output = String::new(); if !repository.is_empty() {