Skip to content

Commit 651caa6

Browse files
committed
tidy error method names
1 parent 8391c44 commit 651caa6

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/ownership/validator.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::rc::Rc;
88

99
use crate::project::{Project, ProjectFile};
1010

11+
use error_stack::Context;
1112
use itertools::Itertools;
1213
use rayon::prelude::IntoParallelRefIterator;
1314
use rayon::prelude::ParallelIterator;
@@ -127,9 +128,9 @@ impl Validator {
127128
}
128129

129130
impl Error {
130-
pub fn title(&self) -> String {
131+
pub fn category(&self) -> String {
131132
match self {
132-
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership:".to_owned(),
133+
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership".to_owned(),
133134
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(),
134135
Error::CodeownershipFileIsStale => {
135136
"CODEOWNERS out of date. Run `codeownership generate` to update the CODEOWNERS file".to_owned()
@@ -157,12 +158,12 @@ impl Error {
157158

158159
impl Display for Errors {
159160
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
160-
let grouped_errors = self.0.iter().into_group_map_by(|error| error.title());
161+
let grouped_errors = self.0.iter().into_group_map_by(|error| error.category());
161162
let grouped_errors = Vec::from_iter(grouped_errors.iter());
162-
let grouped_errors = grouped_errors.iter().sorted_by_key(|(title, _)| title);
163+
let grouped_errors = grouped_errors.iter().sorted_by_key(|(category, _)| category);
163164

164-
for (title, errors) in grouped_errors {
165-
write!(f, "\n{}", title)?;
165+
for (category, errors) in grouped_errors {
166+
write!(f, "\n{}", category)?;
166167

167168
let messages = errors.iter().flat_map(|error| error.messages()).sorted().join("\n");
168169
if !messages.is_empty() {
@@ -177,8 +178,4 @@ impl Display for Errors {
177178
}
178179
}
179180

180-
impl std::error::Error for Errors {
181-
fn description(&self) -> &str {
182-
"Error"
183-
}
184-
}
181+
impl Context for Errors {}

tests/invalid_project_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test_validate() -> Result<(), Box<dyn Error>> {
1111
.assert()
1212
.failure()
1313
.stdout(predicate::str::contains("CODEOWNERS out of date. Run `codeownership generate` to update the CODEOWNERS file"))
14-
.stdout(predicate::str::contains("Some files are missing ownership:\n- ruby/app/unowned.rb"))
14+
.stdout(predicate::str::contains("Some files are missing ownership\n- ruby/app/unowned.rb"))
1515
.stdout(predicate::str::contains("Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways.\n- gems/payroll_calculator/calculator.rb (owner: Payments, source: team_file_mapper)\n- gems/payroll_calculator/calculator.rb (owner: Payroll, source: team_gem_mapper)"));
1616

1717
Ok(())

0 commit comments

Comments
 (0)