Skip to content

Commit 7955da2

Browse files
committed
More helpful error message if kit sound's filename is not a String
Previously this would result in an unhelpful "no implicit conversion of Integer into String" error message. The other scenarios in which a non-String filename is possible (in a kit composite sound or a filename directly referenced in a track name) already showed a more helpful error message.
1 parent 513eaab commit 7955da2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/beats/kit_builder.rb

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def add_item(label, filenames)
3434
@composite_replacements[label] << composite_replacement
3535
end
3636
else
37+
unless filenames.is_a?(String)
38+
raise SoundFileNotFoundError, "Kit sound '#{label}' has an invalid filename: '#{filenames}'. It must be a value that will be parsed from YAML as a String."
39+
end
40+
3741
@labels_to_filenames[label] = absolute_file_name(filenames)
3842
@composite_replacements.delete(label)
3943
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Invalid song, the 'snare' Kit sound has an invalid filename
2+
Song:
3+
Tempo: 120
4+
Flow:
5+
- Verse: x2
6+
Kit:
7+
- bass: test/sounds/bass_mono_8.wav
8+
- snare: 3
9+
- hh_closed: test/sounds/hh_closed_mono_8.wav
10+
- agogo: test/sounds/agogo_high_mono_8.wav
11+
12+
Verse:
13+
- bass: X...X...X...X...
14+
- snare: ..............X.
15+
- hh_closed: X.XXX.XX........
16+
- hh_closed: ........X.X.X.X.
17+
- agogo: ..............XX

test/song_parser_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SongParserTest < Minitest::Test
3232
:track_with_composite_nested_sounds,
3333
:kit_with_composite_nested_sounds,
3434
:kit_not_an_array,
35+
:kit_filename_not_a_string,
3536
:leading_bar_line,
3637
:sound_in_kit_not_found,
3738
:sound_in_track_not_found,

0 commit comments

Comments
 (0)