From 7b10660974dcdd7882a48a62cfc2a32c4a17aa85 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 20 May 2025 17:28:30 -0700 Subject: [PATCH] Use rb_inspect for Ractor error Previously the object was used directly, which calls `to_s` if defined. We should use rb_inspect to get a value suitable for display to the programmer. --- ractor.c | 2 +- test/ruby/test_ractor.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ractor.c b/ractor.c index 75371cfa6f..2388729f83 100644 --- a/ractor.c +++ b/ractor.c @@ -3163,7 +3163,7 @@ make_shareable_check_shareable(VALUE obj) return traverse_cont; } else { - rb_raise(rb_eRactorError, "can not make shareable object for %"PRIsVALUE, obj); + rb_raise(rb_eRactorError, "can not make shareable object for %+"PRIsVALUE, obj); } } diff --git a/test/ruby/test_ractor.rb b/test/ruby/test_ractor.rb index ec94df361f..e61c6beffc 100644 --- a/test/ruby/test_ractor.rb +++ b/test/ruby/test_ractor.rb @@ -60,6 +60,14 @@ class TestRactor < Test::Unit::TestCase assert_unshareable(x, "can not make shareable object for #", exception: Ractor::Error) end + def test_shareability_error_uses_inspect + x = (+"").instance_exec { method(:to_s) } + def x.to_s + raise "this should not be called" + end + assert_unshareable(x, "can not make shareable object for #", exception: Ractor::Error) + end + def test_default_thread_group assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin;