Skip to content

Commit ac17d93

Browse files
SAY-5sds
andauthored
Fail Flay hook when flay crashes instead of silently passing (#885)
The Flay hook only inspects `result.stdout`, so when `flay` crashes (non-zero exit, backtrace on stderr, empty stdout) the hook treats it as "no duplication found" and passes silently. This guards that case: if flay exits non-zero with no stdout, the hook now fails and surfaces stderr, matching how `BerksfileCheck` handles a failed run. Closes #884. --------- Signed-off-by: Sai Asish Y <say.apm35@gmail.com> Co-authored-by: Shane da Silva <shane@dasilva.io>
1 parent bc038b9 commit ac17d93

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/overcommit/hook/pre_commit/flay.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def run
2424
# Run the command for each file
2525
applicable_files.each do |file|
2626
result = execute(command, args: [file])
27+
# flay exits non-zero both when it finds duplication (with output on
28+
# stdout) and when it crashes internally. A crash leaves stdout empty
29+
# and writes a backtrace to stderr, so treat that as an error instead
30+
# of silently passing.
31+
if !result.success? && result.stdout.strip.empty?
32+
return :fail, result.stderr
33+
end
34+
2735
results = result.stdout.split("\n\n")
2836
results.shift
2937
unless results.empty?

spec/overcommit/hook/pre_commit/flay_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@
5757

5858
it { should pass }
5959
end
60+
61+
context 'flay crashed with no output on stdout' do
62+
let(:result) do
63+
double(
64+
success?: false,
65+
stdout: '',
66+
stderr: "undefined method `line' for nil:NilClass (NoMethodError)"
67+
)
68+
end
69+
70+
it { should fail_hook }
71+
end
6072
end

0 commit comments

Comments
 (0)