diff --git a/lib/overcommit/hook/pre_commit/flay.rb b/lib/overcommit/hook/pre_commit/flay.rb index 9876739a..739a325e 100644 --- a/lib/overcommit/hook/pre_commit/flay.rb +++ b/lib/overcommit/hook/pre_commit/flay.rb @@ -24,6 +24,13 @@ def run # Run the command for each file applicable_files.each do |file| result = execute(command, args: [file]) + # flay exits non-zero both when it finds duplication (with output on + # stdout) and when it crashes internally. A crash leaves stdout empty + # and writes a backtrace to stderr, so treat that as an error instead + # of silently passing. + if !result.success? && result.stdout.strip.empty? + return :fail, result.stderr + end results = result.stdout.split("\n\n") results.shift unless results.empty? diff --git a/spec/overcommit/hook/pre_commit/flay_spec.rb b/spec/overcommit/hook/pre_commit/flay_spec.rb index 2a5d8140..2af339bc 100644 --- a/spec/overcommit/hook/pre_commit/flay_spec.rb +++ b/spec/overcommit/hook/pre_commit/flay_spec.rb @@ -57,4 +57,16 @@ it { should pass } end + + context 'flay crashed with no output on stdout' do + let(:result) do + double( + success?: false, + stdout: '', + stderr: "undefined method `line' for nil:NilClass (NoMethodError)" + ) + end + + it { should fail_hook } + end end