Project

General

Profile

Actions

Bug #20607

closed

Exception messages are inconsistent when thread-local variables are accessed

Added by andrykonchin (Andrew Konchin) 5 months ago. Updated 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:118432]

Description

Thread's methods to manipulate thread-local variables raise TypeError exceptions with slightly different messages when the key argument is not a String or a Symbol. The message is either is not a symbol or is not a symbol nor a string. As far as both String and Symbol arguments are correct it seems the is not a symbol nor a string message is more accurate and should be used consistently.

The following methods raise is not a symbol error:

@t.thread_variable_set(:a, 0) # for some methods it's important to have some thread-local variables assigned

@t.thread_variable_get(123) # => 123 is not a symbol (TypeError)
t.thread_variable_set(123, 1) # => 123 is not a symbol (TypeError)
t.thread_variable?(123) # => 123 is not a symbol (TypeError)
t[123] = 1 # => 123 is not a symbol (TypeError)

The following methods raise is not a symbol nor a string error:

t.fetch(123) # => 123 is not a symbol nor a string (TypeError)
t.key?(123) # => 123 is not a symbol nor a string (TypeError)
t[123] # => 123 is not a symbol nor a string (TypeError)

Updated by jeremyevans0 (Jeremy Evans) 5 months ago

I submitted a pull request to make the error message consistent: https://github.com/ruby/ruby/pull/11097

Actions #2

Updated by jeremyevans (Jeremy Evans) 2 months ago

  • Status changed from Open to Closed

Applied in changeset git|8dc0d2904a7d859b463a3f44ac73e5d4540a1cc1.


Update exception message in string_for_symbol

This is a static function only called in two places (rb_to_id and
rb_to_symbol), and in both places, both symbols and strings are
allowed. This makes the error message consistent with rb_check_id
and rb_check_symbol.

Fixes [Bug #20607]

Actions

Also available in: Atom PDF

Like0
Like1Like0