Skip to content

Conversation

@etiennebarrie
Copy link
Member

Improve the messages of exceptions raised by the Ractor implementation.

When an object fails to be made shareable with Ractor.make_shareable or when an unshareable object is accessed through module constants or module instance variables, the error message now includes the chain of references that leads to the unshareable value.

@etiennebarrie etiennebarrie force-pushed the ractor-error-reference-chain branch from d37bed4 to 89a62f7 Compare January 19, 2026 14:29
vm.c Outdated
!RB_OBJ_SHAREABLE_P(block_self)) {
if (!rb_ractor_shareable_p_continue(block_self, chain)) {
if (chain) {
if (NIL_P(*chain)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we duplicating the chain_append logic here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what's the best way to share code here. Should I make the function non-static, prefix it somehow and add it to "ractor_core.h"?

vm.c Outdated
"Proc's self is not shareable: %" PRIsVALUE,
self);
if (chain) {
if (NIL_P(*chain)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here?

" from block self #<Foo @ivar={}>\n" \
" from hash default value\n" \
" from instance variable @ivar\n" \
" from instance variable @foo", %q{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chain approach makes sense to me, but I'm finding the error message a little hard to parse - it's not immediately obvious to me from the message what objects the ivars are attached to, or where the hash values are coming from. Is it worth using rb_inspect or rb_obj_as_string here or is the performance an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a performance issue, it's more that the output gets really messy really fast.

Even in the simple case of just instance variables, it will cause a huge wall of text with a lot of repetition:

class A; attr_accessor :b; end
class B; attr_accessor :c; end
class C; attr_accessor :d; end
class D; attr_accessor :e; end

a = A.new
a.b = b = B.new
b.c = c = C.new
c.d = d = D.new
d.e = ->{}

Ractor.make_shareable a
../../test.rb:12:in 'Ractor.make_shareable': Proc's self is not shareable: #<Proc:0x0000000103731150 ../../test.rb:10 (lambda)> (Ractor::IsolationError)
  from block self main
  from instance variable @e of #<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>
  from instance variable @d of #<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>
  from instance variable @c of #<B:0x00000001037313f0 @c=#<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>>
  from instance variable @b of #<A:0x00000001037314b0 @b=#<B:0x00000001037313f0 @c=#<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>>>
	from ../../test.rb:12:in '<main>'

My first approach always had the object under consideration in addition to the "reference" and it wasn't super readable.

Using this branch I've noticed I usually just need the last line anyway.

Improve the messages of exceptions raised by the Ractor implementation.

When an object fails to be made shareable with `Ractor.make_shareable`
or when an unshareable object is accessed through module constants or
module instance variables, the error message now includes the chain of
references that leads to the unshareable value.
@etiennebarrie etiennebarrie force-pushed the ractor-error-reference-chain branch from 89a62f7 to 2e55ee7 Compare January 23, 2026 13:39
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