Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mask LoadErrors: #249

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/bootsnap/load_path_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ module LoadPathCache
DOT_SO = '.so'
SLASH = '/'

# If a NameError happens several levels deep, don't re-handle it
# all the way up the chain: mark it once and bubble it up without
# more retries.
ERROR_TAG_IVAR = :@__bootsnap_rescued

DL_EXTENSIONS = ::RbConfig::CONFIG
.values_at('DLEXT', 'DLEXT2')
.reject { |ext| !ext || ext.empty? }
Expand Down
13 changes: 4 additions & 9 deletions lib/bootsnap/load_path_cache/core_ext/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ def self.allow_bootsnap_retry(allowed)
Thread.current[:without_bootsnap_retry] = prev
end

# If a NameError happens several levels deep, don't re-handle it
# all the way up the chain: mark it once and bubble it up without
# more retries.
ERROR_TAG_IVAR = :@__bootsnap_rescued

module ClassMethods
def autoload_paths=(o)
super
Expand Down Expand Up @@ -65,8 +60,8 @@ def load_missing_constant(from_mod, const_name)
super
end
rescue NameError => e
raise(e) if e.instance_variable_defined?(ERROR_TAG_IVAR)
e.instance_variable_set(ERROR_TAG_IVAR, true)
raise(e) if e.instance_variable_defined?(Bootsnap::LoadPathCache::ERROR_TAG_IVAR)
e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)

# This function can end up called recursively, we only want to
# retry at the top-level.
Expand All @@ -89,8 +84,8 @@ def load_missing_constant(from_mod, const_name)
def depend_on(*)
super
rescue LoadError => e
raise(e) if e.instance_variable_defined?(ERROR_TAG_IVAR)
e.instance_variable_set(ERROR_TAG_IVAR, true)
raise(e) if e.instance_variable_defined?(Bootsnap::LoadPathCache::ERROR_TAG_IVAR)
e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)

# If we already had cache disabled, there's no use retrying
raise(e) if Thread.current[:without_bootsnap_cache]
Expand Down
10 changes: 10 additions & 0 deletions lib/bootsnap/load_path_cache/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module LoadPathCache
module CoreExt
def self.make_load_error(path)
err = LoadError.new("cannot load such file -- #{path}")
err.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
err.define_singleton_method(:path) { path }
err
end
Expand Down Expand Up @@ -30,6 +31,9 @@ def require(path)
end

raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path))
rescue LoadError => e
e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
raise(e)
rescue Bootsnap::LoadPathCache::ReturnFalse
false
rescue Bootsnap::LoadPathCache::FallbackScan
Expand All @@ -56,6 +60,9 @@ def load(path, wrap = false)
end

raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path))
rescue LoadError => e
e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
raise(e)
rescue Bootsnap::LoadPathCache::ReturnFalse
false
rescue Bootsnap::LoadPathCache::FallbackScan
Expand All @@ -74,6 +81,9 @@ def autoload(const, path)
# added to $LOADED_FEATURES and won't be able to hook that modification
# since it's done in C-land.
autoload_without_bootsnap(const, Bootsnap::LoadPathCache.load_path_cache.find(path) || path)
rescue LoadError => e
e.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
raise(e)
rescue Bootsnap::LoadPathCache::ReturnFalse
false
rescue Bootsnap::LoadPathCache::FallbackScan
Expand Down