@@ -70,21 +70,46 @@ def local_file_system_init() -> AbstractFileSystem:
7070
7171
7272def skip_local_cache (func ):
73+ """Helper function/decorator for handling FileNotFound exception and making
74+ sure that the error is not because of stale cache.
75+
76+ Args:
77+ func: The original function that is called in the context
78+
79+ Returns:
80+ NA
81+ """
82+
7383 def wrapper (* args , ** kwargs ):
7484 try :
7585 return func (* args , ** kwargs )
7686 except FileNotFoundError :
77- try :
78- # FileNotFound could have been caused by stale cache.
79- # Hence invalidate cache and retry again
80- args [0 ].fs .invalidate_cache ()
81- return func (* args , ** kwargs )
82- except Exception as e :
83- if isinstance (e , FileNotFoundError ):
84- raise e
85- else :
86- raise FileOperationError (str (e )) from e
87+ _handle_file_not_found (func , * args , ** kwargs )
8788 except Exception as e :
8889 raise FileOperationError (str (e )) from e
8990
9091 return wrapper
92+
93+
94+ def _handle_file_not_found (func , * args , ** kwargs ):
95+ """Helper function for handling FileNotFound exception and making sure that
96+ the error is not because of stale cache.
97+
98+ Args:
99+ func: The original function that is called in the context
100+ args: The context of the function call as an array
101+ kwargs: args to the function being called in this context
102+
103+ Returns:
104+ NA
105+ """
106+ try :
107+ # FileNotFound could have been caused by stale cache.
108+ # Hence invalidate cache and retry again
109+ args [0 ].fs .invalidate_cache ()
110+ return func (* args , ** kwargs )
111+ except Exception as e :
112+ if isinstance (e , FileNotFoundError ):
113+ raise e
114+ else :
115+ raise FileOperationError (str (e )) from e
0 commit comments