summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNery Campusano <nery.campusano@shopify.com>2026-02-12 16:35:26 -0500
committerKoichi Sasada <ko1@atdot.net>2026-02-13 11:01:50 +0900
commitbe8f647bdab59d16554900c16c101e453863918d (patch)
treeaffef95cc885f1224247a27154e1887548a09a93
parent2233822f3fb6583df4740dd88feaa337f49f05a6 (diff)
[Bug #21551] changing the exception to be isolationerror rather than argument error
-rw-r--r--bootstraptest/test_ractor.rb2
-rw-r--r--doc/language/ractor.md4
-rw-r--r--ractor.rb4
-rw-r--r--test/ruby/test_iseq.rb2
-rw-r--r--test/ruby/test_ractor.rb18
-rw-r--r--vm.c4
6 files changed, 26 insertions, 8 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index e2a3e8dd5b..9242dce7dc 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -803,7 +803,7 @@ assert_equal 'true', %q{
}
# given block Proc will be isolated, so can not access outer variables.
-assert_equal 'ArgumentError', %q{
+assert_equal 'Ractor::IsolationError', %q{
begin
a = true
r = Ractor.new do
diff --git a/doc/language/ractor.md b/doc/language/ractor.md
index a0acaf3a91..1592656217 100644
--- a/doc/language/ractor.md
+++ b/doc/language/ractor.md
@@ -97,10 +97,10 @@ This isolation occurs at Ractor creation time (when `Ractor.new` is called). If
begin
a = true
r = Ractor.new do
- a #=> ArgumentError because this block accesses outer variable `a`.
+ a #=> Ractor::IsolationError because this block accesses outer variable `a`.
end
r.join # wait for ractor to finish
-rescue ArgumentError
+rescue Ractor::IsolationError
end
```
diff --git a/ractor.rb b/ractor.rb
index ac04237fc6..2dc60f5ff6 100644
--- a/ractor.rb
+++ b/ractor.rb
@@ -15,7 +15,7 @@
# a = 1
# r = Ractor.new {puts "I am in Ractor! a=#{a}"}
# # fails immediately with
-# # ArgumentError (can not isolate a Proc because it accesses outer variables (a).)
+# # Ractor::IsolationError (can not isolate a Proc because it accesses outer variables (a).)
#
# The object must be explicitly shared:
# a = 1
@@ -657,7 +657,7 @@ class Ractor
#
# a = 42
# Ractor.shareable_proc{ p a }
- # #=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError)
+ # #=> can not isolate a Proc because it accesses outer variables (a). (Ractor::IsolationError)
#
# The value of `self` in the Proc must be a shareable object.
#
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index fa716787fe..6846f7958b 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -157,7 +157,7 @@ class TestISeq < Test::Unit::TestCase
def test_ractor_unshareable_outer_variable
name = "\u{2603 26a1}"
- assert_raise_with_message(ArgumentError, /\(#{name}\)/) do
+ assert_raise_with_message(Ractor::IsolationError, /\(#{name}\)/) do
eval("#{name} = nil; Ractor.shareable_proc{#{name} = nil}")
end
diff --git a/test/ruby/test_ractor.rb b/test/ruby/test_ractor.rb
index 6ae511217a..36467a3591 100644
--- a/test/ruby/test_ractor.rb
+++ b/test/ruby/test_ractor.rb
@@ -213,6 +213,24 @@ class TestRactor < Test::Unit::TestCase
assert_unshareable(pr, /not supported yet/, exception: RuntimeError)
end
+ def test_ractor_new_raises_isolation_error_if_outer_variables_are_accessed
+ assert_raise(Ractor::IsolationError) do
+ channel = Ractor::Port.new
+ Ractor.new(channel) do
+ inbound_work = Ractor::Port.new
+ channel << inbound_work
+ end
+ end
+ end
+
+ def test_ractor_new_raises_isolation_error_if_proc_uses_yield
+ assert_raise(Ractor::IsolationError) do
+ Ractor.new do
+ yield
+ end
+ end
+ end
+
def assert_make_shareable(obj)
refute Ractor.shareable?(obj), "object was already shareable"
Ractor.make_shareable(obj)
diff --git a/vm.c b/vm.c
index a9e952f705..a078f9e734 100644
--- a/vm.c
+++ b/vm.c
@@ -1521,10 +1521,10 @@ proc_shared_outer_variables(struct rb_id_table *outer_variables, bool isolate, c
}
if (*sep == ',') rb_str_cat_cstr(str, ")");
rb_str_cat_cstr(str, data.yield ? " and uses 'yield'." : ".");
- rb_exc_raise(rb_exc_new_str(rb_eArgError, str));
+ rb_exc_raise(rb_exc_new_str(rb_eRactorIsolationError, str));
}
else if (data.yield) {
- rb_raise(rb_eArgError, "can not %s because it uses 'yield'.", message);
+ rb_raise(rb_eRactorIsolationError, "can not %s because it uses 'yield'.", message);
}
return data.read_only;