Skip to content

[Bug #21551] - Change Ractor Proc isolation error from ArgumentError to Ractor::IsolationError - #16163

Merged
ko1 merged 1 commit into
ruby:masterfrom
Shopify:nc/change_arg_error_to_isolation_error_for_ractor_proc
Feb 13, 2026
Merged

[Bug #21551] - Change Ractor Proc isolation error from ArgumentError to Ractor::IsolationError #16163
ko1 merged 1 commit into
ruby:masterfrom
Shopify:nc/change_arg_error_to_isolation_error_for_ractor_proc

Conversation

@AlexaCampusano

@AlexaCampusano AlexaCampusano commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes https://bugs.ruby-lang.org/issues/21551

When Ractor.new is called with a block that references outer variables, the error raised is an ArgumentError. Because ErrorHighlight treats ArgumentError specially (highlighting the arguments of the method call) the squiggly underline points to the wrong place.

channel = Ractor::Port.new

coordinator = Ractor.new(channel) do
  inbound_work = Ractor::Port.new
  channel << inbound_work
end
> ruby thing.rb
thing.rb:3: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
thing.rb:3:in 'Ractor.new': can not isolate a Proc because it accesses outer variables (channel). (ArgumentError)

coordinator = Ractor.new(channel) do
                         ^^^^^^^
	from thing.rb:3:in '<main>'

The squiggly points at channel in Ractor.new(channel), which is the correct way to pass data into a Ractor. The actual problem is channel being referenced inside the block body without a corresponding block parameter |channel|.

This happens because ErrorHighlight sets point_type: :args for ArgumentError, which tells it to highlight the arguments of the call (it doesn't highlight just channel).

Solution

I'm proposing a multi-step approach:

Step 1: Raise Ractor::IsolationError instead of ArgumentError [this PR changes]

  • For one, Ractor.shareable_proc raises Ractor::IsolationError for a similar situation - a Proc that references outer variables that can't be shared.
def foo
  foo = 123
  x = Ractor.shareable_proc do
    foo   # Ractor::IsolationError
  end
  foo = 456
end
foo
  • Secondly, I don't believe this is an argument error. The arguments to Ractor.new are valid, it's the use of outer variables inside the block that violates Ractor isolation.
  • Lastly, it will eliminate the misleading error highlight. With a different exception class, ErrorHighlight no longer applies its ArgumentError-specific :args highlighting, so the squiggly stops pointing at the arguments. This will be iterated in follow up PRs.

Step 2: Enhance Ractor::IsolationError to hold a reference to the list of outer variables used in the proc [Next PRs] 📝

Enrich the exception class with the list of outer variables referenced in the Proc, so that this information is available to ErrorHighlight.

Step 3: Create a custom error highlitghting case for Ractor::IsolationError so we can highlight the uses of these [Next PRs] variables inside the proc 📝

Use the variable information from step 2 to highlight the actual uses of the outer variables inside the block body, rather than the call site.

@ioquatix
ioquatix requested a review from ko1 February 13, 2026 01:59
@ko1
ko1 merged commit be8f647 into ruby:master Feb 13, 2026
92 checks passed
@ko1

ko1 commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants