Skip to content

Commit

Permalink
chore: unify log and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bajankristof committed May 6, 2024
1 parent 7e22451 commit f0b8be9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
27 changes: 20 additions & 7 deletions lib/ffmpeg/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,26 @@ def validate_output_file

if succeeded?
yield(1.0) if block_given?
FFMPEG.logger.info "Transcoding of #{@input_path} to #{@output_path} succeeded\n"
FFMPEG.logger.info(self.class) do
"Transcoding #{@input_path} to #{@output_path} succeeded\n" \
"Command: #{command.join(' ')}\n" \
"Output: #{@output}"
end
else
errors = "Errors: #{@errors.join(', ')}. "
FFMPEG.logger.error "Failed encoding...\n#{command.join(' ')}\n\n#{@output}\n#{errors}\n"
raise Error, "Failed encoding. #{errors}Full output: #{@output}"
message = "Transcoding #{@input_path} to #{@output_path} failed\n" \
"Command: #{command.join(' ')}\n" \
"Errors: #{@errors.join(', ')}\n " \
"Output: #{@output}\n"
FFMPEG.logger.error(self.class) { message }
raise Error, message
end
end

def execute
FFMPEG.logger.info("Running transcoding...\n#{command.join(' ')}\n")
FFMPEG.logger.info(self.class) do
"Transcoding #{@input_path} to #{@output_path}...\n" \
"Command: #{command.join(' ')}"
end

@output = String.new

Expand All @@ -175,9 +185,12 @@ def execute

@errors << 'ffmpeg returned non-zero exit code' unless wait_thr.value.success?
rescue Timeout::Error
message = "Transcoding #{@input_path} to #{@output_path} failed, process hung\n" \
"Command: #{command.join(' ')}\n" \
"Output: #{@output}"
Process.kill(FFMPEG::SIGKILL, wait_thr.pid)
FFMPEG.logger.error "Process hung...\n#{command.join(' ')}\nOutput\n#{@output}\n"
raise Error, "Process hung. Full output: #{@output}"
FFMPEG.logger.error(self.class) { message }
raise Error, message
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ffmpeg/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FFMPEG
VERSION = '5.0.0'
VERSION = '5.0.1'
end
6 changes: 3 additions & 3 deletions spec/ffmpeg/transcoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module FFMPEG

it 'should fail when the timeout is exceeded' do
expect(FFMPEG.logger).to receive(:error)
expect { subject.run }.to raise_error(FFMPEG::Error, /Process hung/)
expect { subject.run }.to raise_error(FFMPEG::Error, /Transcoding .+ failed, process hung/)
end
end

Expand Down Expand Up @@ -150,7 +150,7 @@ module FFMPEG
end

it 'should fail when the timeout is exceeded' do
expect { subject.run }.to raise_error(FFMPEG::Error, /Process hung/)
expect { subject.run }.to raise_error(FFMPEG::Error, /Transcoding .+ failed, process hung/)
end
end
end
Expand Down Expand Up @@ -298,7 +298,7 @@ module FFMPEG
it 'should fail' do
expect do
subject.run
end.to raise_error(FFMPEG::Error, /Failed encoding/)
end.to raise_error(FFMPEG::Error, /Transcoding .+ failed/)
end
end

Expand Down

0 comments on commit f0b8be9

Please sign in to comment.