Project

General

Profile

Actions

Feature #19849

open

Requiring file with autoload results in confusing error if file doesn't exist

Added by p8 (Petrik de Heus) 9 months ago. Updated 8 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:114501]

Description

Given the following file that calls the Example constant:

# example.rb
require_relative 'autoload_example.rb'

Example.new

and an autoload to define the Example constant, with an unknown path:

# autoload_example.rb
autoload "Example", "path_unknown"

Running ruby example.rb results in the following error:

<internal:~/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- path_unknown (LoadError)
	from <internal:~/.rubies/ruby-3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from example.rb:4:in `<main>'

The error is somewhat confusing as it doesn't show the location of the autoload which caused the error.
This can be especially confusing if the autoload is called somewhere deep in a gem.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0