Project

General

Profile

Actions

Bug #21760

open

Ruby::Box: a couple of require-related problems

Bug #21760: Ruby::Box: a couple of require-related problems

Added by zverok (Victor Shepelev) 3 months ago. Updated 9 days ago.

Status:
Assigned
Target version:
-
ruby -v:
4.0.0dev (2025-12-03T05:16:03Z master 4762f429f4) +PRISM [x86_64-linux]
[ruby-core:123992]
Tags:

Description

I am not sure whether all the problems have the same nature, but putting them together for now.

1. Enabling box breaks gem+require

Minimal reproducible example:

test.rb:

gem 'faraday', '= 2.14.0'
require 'faraday'
p Faraday::VERSION

(Note that there is no explicit use of Ruby::Box)

Running it with and without RUBY_BOX:

$ ruby test.rb
"2.14.0"

$ RUBY_BOX=1 ruby test.rb 
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/box.md for known issues, etc.
test.rb:2:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from test.rb:2:in 'Ruby::Box::Loader#require'
	from test.rb:2:in '<main>'
test.rb:2:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from test.rb:2:in 'Ruby::Box::Loader#require'
	from test.rb:2:in '<main>'

(sic, the error is printed twice)

2. requiring the same gem from Box-loaded file and the main file

box.rb:

require 'faraday'
p "In a box: #{Faraday::VERSION}"

main.rb

b = Ruby::Box.new

b.load('box.rb')

require 'faraday'
$ RUBY_BOX=1 ruby main.rb
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/box.md for known issues, etc.
"In a box: 2.14.0"
main.rb:5:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from main.rb:5:in 'Ruby::Box::Loader#require'
	from main.rb:5:in '<main>'
main.rb:5:in 'Kernel#require': cannot load such file -- faraday (LoadError)
	from main.rb:5:in 'Ruby::Box::Loader#require'
	from main.rb:5:in '<main>'

3. Box#require seem to not be aware of gems

In the example above, we see that Box-loaded file can require a gem.

This also works:

b = Ruby::Box.new

b.eval(<<~RUBY)
  require "faraday"

  p Faraday::VERSION
RUBY

(prints "2.14.0" as expected)

But this doesn't:

b = Ruby::Box.new

b.require('faraday')
$ RUBY_BOX=1 ruby test.rb 
ruby: warning: Ruby::Box is experimental, and the behavior may change in the future!
See doc/language/box.md for known issues, etc.
test.rb:3:in 'Ruby::Box#require': cannot load such file -- faraday (LoadError)
	from test.rb:3:in '<main>'

Updated by mame (Yusuke Endoh) 3 months ago Actions #1 [ruby-core:124086]

  • Status changed from Open to Assigned
  • Assignee set to tagomoris (Satoshi Tagomori)

Updated by hsbt (Hiroshi SHIBATA) 3 months ago Actions #2

  • Tags set to box

Updated by katsyoshi (Katsuyoshi MATSUMOTO) 9 days ago Actions #3 [ruby-core:124954]

I found another Ruby::Box#require case that seems related to this issue.

Environment

  • 4.0.1 / linux
  • RUBY_BOX=1

If a file loaded inside Ruby::Box requires fiddle/import, loading the same file from multiple boxes can fail
with:

LoadError: cannot load such file -- fiddle/import

Reproducer

require "fiddle/import"
abox = Ruby::Box.new
bbox = Ruby::Box.new

abox.require "./import.rb"
bbox.require "./import.rb"

Interestingly, requiring time from multiple boxes works in the same environment, so this may be specific to
fiddle/import, or more generally to ext/stdlib loading through Ruby::Box.

The current box documentation seems to suggest that dependencies required from a file loaded via Ruby::Box should
also be loaded recursively within that box, so this looked like another require-related inconsistency to me.

If this is expected behavior, it may need to be documented as a limitation. Otherwise, this may belong in the same
family of Ruby::Box#require bugs tracked here.

Actions

Also available in: PDF Atom