Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/wavesync/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def transcode(target_path, target_sample_rate: nil, target_file_type: nil, targe
yield temp_path if block_given?
Timing.current.measure(:copy) { FileUtils.install(temp_path, target_path) }
true
rescue Errno::ENOENT => e
rescue SystemCallError => e
Logger.log_error(e, call_site: 'Audio#transcode', arguments: { target_path:, target_sample_rate:, target_file_type:, target_bit_depth:, padding_seconds:, target_bitrate: })
false
ensure
Expand Down
2 changes: 1 addition & 1 deletion lib/wavesync/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def rescale_cue_points(cue_points, source_sample_rate, target_sample_rate)
#: (String source, Pathname target) -> void
def safe_copy(source, target)
Timing.current.measure(:copy) { FileUtils.install(source, target) }
rescue Errno::ENOENT => e
rescue SystemCallError => e
Logger.log_error(e, call_site: 'Scanner#safe_copy', arguments: { source:, target: })
end

Expand Down
19 changes: 19 additions & 0 deletions test/wavesync/audio_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ class AudioTest < Wavesync::TestCase
assert_equal false, result
end

test 'transcode returns false and logs error when EINVAL is raised' do
audio_obj = audio('44100_16.wav')
FileUtils.stubs(:install).raises(Errno::EINVAL)
Logger.expects(:log_error).with(
instance_of(Errno::EINVAL),
call_site: 'Audio#transcode',
arguments: {
target_path: '/tmp/output.mp3',
target_sample_rate: nil,
target_file_type: 'mp3',
target_bit_depth: 16,
padding_seconds: nil,
target_bitrate: 192
}
)
result = audio_obj.transcode('/tmp/output.mp3', target_file_type: 'mp3', target_bit_depth: 16)
assert_equal false, result
end

private

def audio(name)
Expand Down
14 changes: 14 additions & 0 deletions test/wavesync/scanner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ def teardown
Scanner.new(@source_dir).sync(@target_dir, @device)
end

test 'safe_copy logs error and continues syncing when EINVAL is raised' do
source_wav = File.join(File.expand_path(@source_dir), 'track.wav')
FileUtils.cp(fixture('44100_16.wav'), source_wav)

expected_target = Pathname(File.join(File.expand_path(@target_dir), 'TRACK.WAV'))
FileUtils.stubs(:install).raises(Errno::EINVAL)
Logger.expects(:log_error).with(
instance_of(Errno::EINVAL),
call_site: 'Scanner#safe_copy',
arguments: { source: source_wav, target: expected_target }
)
Scanner.new(@source_dir).sync(@target_dir, @device)
end

private

def fixture(name)
Expand Down
Loading