diff --git a/lib/wavesync/audio.rb b/lib/wavesync/audio.rb index 25c930c..ff50f69 100644 --- a/lib/wavesync/audio.rb +++ b/lib/wavesync/audio.rb @@ -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 diff --git a/lib/wavesync/scanner.rb b/lib/wavesync/scanner.rb index 57eaf49..9958552 100644 --- a/lib/wavesync/scanner.rb +++ b/lib/wavesync/scanner.rb @@ -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 diff --git a/test/wavesync/audio_test.rb b/test/wavesync/audio_test.rb index 3500684..2d6c658 100644 --- a/test/wavesync/audio_test.rb +++ b/test/wavesync/audio_test.rb @@ -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) diff --git a/test/wavesync/scanner_test.rb b/test/wavesync/scanner_test.rb index ebcc56b..efc066b 100644 --- a/test/wavesync/scanner_test.rb +++ b/test/wavesync/scanner_test.rb @@ -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)