Skip to content

Commit fd38b53

Browse files
committed
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.
1 parent bb519a8 commit fd38b53

File tree

4 files changed

+1
-22
lines changed

4 files changed

+1
-22
lines changed

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

lib/code_ownership.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ 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-
)
239234
end
240235

241236
# Removes the file annotation (e.g., "# @team TeamName") from a file.
7.73 MB
Binary file not shown.

spec/lib/code_ownership_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -555,20 +555,4 @@
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
574558
end

0 commit comments

Comments
 (0)