Skip to content

Commit bc5d0ae

Browse files
committed
Core - improve error message with bad SPVector index
1 parent 7e3c90e commit bc5d0ae

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

app/server/core.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def self.reset_all
184184
module SonicPi
185185
module Core
186186
class EmptyVectorError < StandardError ; end
187+
class InvalidIndexError < StandardError ; end
187188

188189
class SPVector < Hamster::Vector
189190
include TLMixin
@@ -201,6 +202,7 @@ def ___sp_preserve_vec_kind(a)
201202
end
202203

203204
def [](idx, len=(missing_length = true))
205+
raise InvalidIndexError, "Invalid index: #{idx.inspect}, was expecting a number or range" unless idx && (idx.is_a?(Numeric) || idx.is_a?(Range))
204206
if idx.is_a?(Numeric) && missing_length
205207
idx = map_index(idx)
206208
super idx

0 commit comments

Comments
 (0)