Skip to content

Commit bb519a8

Browse files
committed
Fix misleading error message when CODEOWNERS is out of date
When running `codeownership validate --skip-autocorrect` with an out-of-date CODEOWNERS file, the error from codeowners-rs says to run `codeowners generate`, which is the standalone Rust CLI and not available to users of this gem. Rewrite the message to point to `bin/codeownership validate` instead. Fixes #155
1 parent 739a83c commit bb519a8

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/code_ownership.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ def self.validate!(
231231
else
232232
::RustCodeOwners.validate(files)
233233
end
234+
rescue RuntimeError => e
235+
raise e.message.gsub(
236+
'Run `codeowners generate` to update the CODEOWNERS file',
237+
'Run `bin/codeownership validate` to update the CODEOWNERS file'
238+
)
234239
end
235240

236241
# Removes the file annotation (e.g., "# @team TeamName") from a file.

spec/lib/code_ownership_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,20 @@
555555
end
556556
end
557557
end
558+
559+
describe '.validate!' do
560+
context 'when RustCodeOwners raises a codeowners-rs error about the CODEOWNERS file being out of date' do
561+
it 'rewrites the error message to reference bin/codeownership validate' do
562+
allow(RustCodeOwners).to receive(:validate).and_raise(
563+
RuntimeError,
564+
"CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file"
565+
)
566+
567+
expect { CodeOwnership.validate!(autocorrect: false) }.to raise_error(
568+
RuntimeError,
569+
"CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file"
570+
)
571+
end
572+
end
573+
end
558574
end

0 commit comments

Comments
 (0)