Skip to content

Commit a3be7aa

Browse files
authored
Merge pull request #2871 from owenniblock/fix/throw-better-error-on-sample-duration
2 parents 92be386 + 4c048be commit a3be7aa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

app/server/ruby/lib/sonicpi/lang/sound.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,11 @@ def sample_buffer(*args)
22152215
def sample_duration(*args)
22162216
filts_and_sources, args_a = sample_split_filts_and_opts(args)
22172217
path = resolve_sample_path(filts_and_sources)
2218+
2219+
if path.nil?
2220+
raise ArgumentError.new("Error calling sample_duration: filters matched no samples")
2221+
end
2222+
22182223
dur = load_sample_at_path(path).duration
22192224
args_h = merge_synth_arg_maps_array(args_a)
22202225

app/server/ruby/test/lang/sound/test_sound.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ def test_should_trigger
5050
assert_equal(true, @mock_sound.should_trigger?(h))
5151
end
5252

53+
def test_sample_duration
54+
@mock_sound.stub :resolve_sample_path, nil do
55+
assert_raises(ArgumentError) { @mock_sound.sample_duration(["a/directory", "bogus_file_name"]) }
56+
end
57+
end
5358
end
5459
end

0 commit comments

Comments
 (0)