
Issue #19849 has been updated by mame (Yusuke Endoh). Briefly discussed at the dev meeting. We understand the problem, but doesn't find a good solution. Since the call line of autoload does not exist in the call stack when the exception occurs, it cannot be displayed as a backtrace. It may be possible to include it in an error message or `Exception#cause`. If there are specific suggestions on how to actually implement it and how to display it, it could be considered. ---------------------------------------- Feature #19849: Requiring file with autoload results in confusing error if file doesn't exist https://bugs.ruby-lang.org/issues/19849#change-104593 * Author: p8 (Petrik de Heus) * Status: Open * Priority: Normal ---------------------------------------- Given the following file that calls the `Example` constant: ```ruby # example.rb require_relative 'autoload_example.rb' Example.new ``` and an autoload to define the `Example` constant, with an unknown path: ```ruby # 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. -- https://bugs.ruby-lang.org/