@@ -19,6 +19,7 @@ module Kernel
1919 alias_method ( :require_without_bootsnap , :require )
2020
2121 def require ( path )
22+ fallback = false
2223 string_path = path . to_s
2324 return false if Bootsnap ::LoadPathCache . loaded_features_index . key? ( string_path )
2425
@@ -36,13 +37,19 @@ def require(path)
3637 rescue Bootsnap ::LoadPathCache ::ReturnFalse
3738 false
3839 rescue Bootsnap ::LoadPathCache ::FallbackScan
39- if ( cursor = Bootsnap ::LoadPathCache . loaded_features_index . cursor ( string_path ) )
40- ret = require_without_bootsnap ( path )
41- resolved = Bootsnap ::LoadPathCache . loaded_features_index . identify ( string_path , cursor )
42- Bootsnap ::LoadPathCache . loaded_features_index . register ( string_path , resolved )
43- ret
44- else # If we're not given a cursor, it means we don't need to register the path (likely an absolute path)
45- require_without_bootsnap ( path )
40+ fallback = true
41+ ensure
42+ # We raise from `ensure` so that any further exception don't have FallbackScan as a cause
43+ # See: https://github.com/Shopify/bootsnap/issues/250
44+ if fallback
45+ if ( cursor = Bootsnap ::LoadPathCache . loaded_features_index . cursor ( string_path ) )
46+ ret = require_without_bootsnap ( path )
47+ resolved = Bootsnap ::LoadPathCache . loaded_features_index . identify ( string_path , cursor )
48+ Bootsnap ::LoadPathCache . loaded_features_index . register ( string_path , resolved )
49+ ret
50+ else # If we're not given a cursor, it means we don't need to register the path (likely an absolute path)
51+ require_without_bootsnap ( path )
52+ end
4653 end
4754 end
4855
@@ -68,6 +75,7 @@ def load(path, wrap = false)
6875class Module
6976 alias_method ( :autoload_without_bootsnap , :autoload )
7077 def autoload ( const , path )
78+ fallback = false
7179 # NOTE: This may defeat LoadedFeaturesIndex, but it's not immediately
7280 # obvious how to make it work. This feels like a pretty niche case, unclear
7381 # if it will ever burn anyone.
@@ -82,6 +90,10 @@ def autoload(const, path)
8290 rescue Bootsnap ::LoadPathCache ::ReturnFalse
8391 false
8492 rescue Bootsnap ::LoadPathCache ::FallbackScan
93+ fallback = true
94+ ensure
95+ # We raise from `ensure` so that any further exception don't have FallbackScan as a cause
96+ # See: https://github.com/Shopify/bootsnap/issues/250
8597 autoload_without_bootsnap ( const , path )
8698 end
8799end
0 commit comments