Skip to content

Commit 5b1da86

Browse files
committed
🥅 Improve ArgumentError in SequenceSet#string=
1 parent c3c52e4 commit 5b1da86

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,16 @@ def deconstruct; valid? ? [normalized_string] : [] end
574574
# Use #add, #merge, or #append to add a string to an existing set.
575575
#
576576
# Related: #replace, #clear
577-
def string=(str)
578-
if str.nil?
577+
def string=(input)
578+
if input.nil?
579579
clear
580-
else
581-
modifying! # redundant check, to normalize the error message for JRuby
582-
str = String.try_convert(str) or raise ArgumentError, "not a string"
580+
elsif (str = String.try_convert(input))
581+
modifying! # short-circuit before parsing the string
583582
tuples = str_to_tuples str
584583
@tuples, @string = [], -str
585584
tuples_add tuples
585+
else
586+
raise ArgumentError, "expected a string or nil, got #{input.class}"
586587
end
587588
str
588589
end

0 commit comments

Comments
 (0)