Skip to content

Commit 863ebc7

Browse files
authored
Fix misleading error message when CODEOWNERS is out of date (#164)
* 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 * Replace Ruby-level error rewrite with fix at source in codeowners-rs Instead of rescuing RuntimeError in validate! and doing a fragile gsub on the error message string, pass executable_name to RunConfig so codeowners-rs generates the correct message directly. This requires a companion change in codeowners-rs that changes executable_name to hold the full command (e.g. "codeowners generate") rather than just the binary name, so the format string no longer hardcodes the " generate" subcommand. * Add spec for validate! error message referencing bin/codeownership validate Verifies that when CODEOWNERS is out of date and validate! is called with autocorrect: false, the error message references bin/codeownership validate rather than the standalone codeowners generate CLI command.
1 parent 739a83c commit 863ebc7

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

ext/code_ownership/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn build_run_config() -> RunConfig {
116116
codeowners_file_path: None,
117117
config_path,
118118
no_cache: false,
119-
executable_name: None,
119+
executable_name: Some("bin/codeownership validate".to_string()),
120120
}
121121
}
122122

7.73 MB
Binary file not shown.

spec/lib/code_ownership_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,28 @@
555555
end
556556
end
557557
end
558+
559+
describe '.validate!' do
560+
context 'when the CODEOWNERS file is out of date' do
561+
before do
562+
create_non_empty_application
563+
RustCodeOwners.generate_and_validate(nil, false)
564+
# Add a new annotated file to make the CODEOWNERS file out of date
565+
write_file('packs/my_pack/new_file.rb', "# @team Bar\nclass NewFile; end\n")
566+
end
567+
568+
it 'raises an error referencing bin/codeownership validate' do
569+
expect { CodeOwnership.validate!(autocorrect: false) }.to raise_error(
570+
RuntimeError,
571+
/Run `bin\/codeownership validate/
572+
)
573+
end
574+
575+
it 'does not reference the standalone codeowners CLI' do
576+
expect { CodeOwnership.validate!(autocorrect: false) }.to raise_error(RuntimeError) do |error|
577+
expect(error.message).not_to include('`codeowners generate`')
578+
end
579+
end
580+
end
581+
end
558582
end

0 commit comments

Comments
 (0)