Skip to content

Commit 8391c44

Browse files
committed
fix non determinism of error messages
1 parent 539ece7 commit 8391c44

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/ownership/validator.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Validator {
127127
}
128128

129129
impl Error {
130-
pub fn error_category_message(&self) -> String {
130+
pub fn title(&self) -> String {
131131
match self {
132132
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership:".to_owned(),
133133
Error::FileWithMultipleOwners { path: _, owners: _ } => "Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways.".to_owned(),
@@ -137,35 +137,37 @@ impl Error {
137137
}
138138
}
139139

140-
pub fn error_message(&self) -> String {
140+
pub fn messages(&self) -> Vec<String> {
141141
match self {
142-
Error::FileWithoutOwner { path } => format!("- {}", path.to_string_lossy()),
142+
Error::FileWithoutOwner { path } => vec![format!("- {}", path.to_string_lossy())],
143143
Error::FileWithMultipleOwners { path, owners } => owners
144144
.iter()
145145
.flat_map(|owner| {
146146
owner
147147
.sources
148148
.iter()
149149
.map(|source| format!("- {} (owner: {}, source: {})", path.to_string_lossy(), owner.team_name, &source))
150+
.collect_vec()
150151
})
151-
.join("\n"),
152-
Error::CodeownershipFileIsStale => "".to_owned(),
152+
.collect_vec(),
153+
Error::CodeownershipFileIsStale => vec![],
153154
}
154155
}
155156
}
156157

157158
impl Display for Errors {
158159
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
159-
let grouped_errors = self.0.iter().into_group_map_by(|error| error.error_category_message());
160+
let grouped_errors = self.0.iter().into_group_map_by(|error| error.title());
160161
let grouped_errors = Vec::from_iter(grouped_errors.iter());
162+
let grouped_errors = grouped_errors.iter().sorted_by_key(|(title, _)| title);
161163

162-
for (error_category_message, errors) in grouped_errors {
163-
write!(f, "\n{}", error_category_message)?;
164+
for (title, errors) in grouped_errors {
165+
write!(f, "\n{}", title)?;
164166

165-
let error_messages = errors.iter().map(|error| error.error_message()).join("\n");
166-
if !error_messages.is_empty() {
167+
let messages = errors.iter().flat_map(|error| error.messages()).sorted().join("\n");
168+
if !messages.is_empty() {
167169
writeln!(f)?;
168-
write!(f, "{}", error_messages)?;
170+
write!(f, "{}", &messages)?;
169171
}
170172

171173
writeln!(f)?;

0 commit comments

Comments
 (0)