1616class ErrorClassifierTest (unittest .TestCase ):
1717 EXECUTOR_MODULE = data_job .__file__
1818 EXECUTOR_MODULE_DIR = os .path .dirname (EXECUTOR_MODULE )
19+ INGESTOR_MODULE_DIR = os .path .dirname (EXECUTOR_MODULE ).replace ("run" , "ingestion" )
20+
21+ PLATFORM_ERROR_EXTERNAL_LIBRARY = [
22+ """
23+ File "/opt/homebrew/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 912, in read_csv
24+ """ ,
25+ """
26+ File "{}/job_input.py", line 155, in send_tabular_data_for_ingestion
27+ """ .format (
28+ EXECUTOR_MODULE_DIR
29+ ),
30+ """
31+ File "{}/file_based_step.py", line 139, in invoke_run_function
32+ """ .format (
33+ EXECUTOR_MODULE_DIR
34+ ),
35+ """
36+ File "{}", line 9, in run
37+ """ .format (
38+ os .path .join ("job" , "moonshine-ri" , "21-find-ri-optimal.py" )
39+ ),
40+ """
41+ File "{}/ingester_router.py", line 142, in send_tabular_data_for_ingestion
42+ """ .format (
43+ INGESTOR_MODULE_DIR
44+ ),
45+ ]
46+
47+ USER_ERROR_USER_PROVIDED_ITERATOR = [
48+ """
49+ File "{}", line 9, in run
50+ """ .format (
51+ os .path .join ("job" , "moonshine-ri" , "21-find-ri-optimal.py" )
52+ ),
53+ """
54+ File "{}/job_input.py", line 155, in send_tabular_data_for_ingestion
55+ """ .format (
56+ EXECUTOR_MODULE_DIR
57+ ),
58+ """
59+ File "{}", line 5, in run
60+ """ .format (
61+ os .path .join ("job" , "moonshine-ri" , "21-find-ri-optimal.py" )
62+ ),
63+ """
64+ File "{}/ingester_router.py", line 142, in send_tabular_data_for_ingestion
65+ """ .format (
66+ INGESTOR_MODULE_DIR
67+ ),
68+ ]
69+
70+ USER_ERROR_USER_PROVIDED_ITERATOR_EXTERNAL_LIBRARY = [
71+ """
72+ File "/opt/homebrew/lib/python3.11/site-packages/pandas/io/parsers/readers.py", line 912, in read_csv
73+ """ ,
74+ """
75+ File "{}/job_input.py", line 155, in send_tabular_data_for_ingestion
76+ """ .format (
77+ EXECUTOR_MODULE_DIR
78+ ),
79+ """
80+ File "{}", line 5, in run
81+ """ .format (
82+ os .path .join ("job" , "moonshine-ri" , "21-find-ri-optimal.py" )
83+ ),
84+ """
85+ File "{}/ingester_router.py", line 142, in send_tabular_data_for_ingestion
86+ """ .format (
87+ INGESTOR_MODULE_DIR
88+ ),
89+ ]
90+
1991 USER_ERROR_STACKTRACE = [
2092 """File "{exec_module}", line 123, in _run_step
2193 step_executed = runner_func(file_path)""" .format (
@@ -65,15 +137,15 @@ class ErrorClassifierTest(unittest.TestCase):
65137 def test_vdk_user_code_error (self ):
66138 exception = errors .UserCodeError ("User error" )
67139 self .assertEqual (
68- whom_to_blame (exception , self .EXECUTOR_MODULE ),
69140 errors .ResolvableBy .USER_ERROR ,
141+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
70142 )
71143
72144 def test_vdk_platform_service_error (self ):
73145 exception = errors .PlatformServiceError ("Platform error" )
74146 self .assertEqual (
75- whom_to_blame (exception , self .EXECUTOR_MODULE ),
76147 errors .ResolvableBy .PLATFORM_ERROR ,
148+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
77149 )
78150
79151 # Test generic errors specifically recognised as user errors by VDK.
@@ -82,8 +154,8 @@ def test_known_generic_error(self, mock_is_user_error):
82154 mock_is_user_error .return_value = True
83155 exception = Exception ("User Error" )
84156 self .assertEqual (
85- whom_to_blame (exception , self .EXECUTOR_MODULE ),
86157 errors .ResolvableBy .USER_ERROR ,
158+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
87159 )
88160
89161 # Test generic errors that are not specifically recognised by VDK.
@@ -94,8 +166,8 @@ def test_unknown_generic_error(self, mock_is_user_error, mock_traceback_format_t
94166 mock_is_user_error .return_value = False
95167 mock_traceback_format_tb .return_value = self .USER_ERROR_STACKTRACE
96168 self .assertEqual (
97- whom_to_blame (exception , self .EXECUTOR_MODULE ),
98169 errors .ResolvableBy .USER_ERROR ,
170+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
99171 )
100172
101173 # Test generic errors in user code that are not specifically recognised by VDK.
@@ -106,10 +178,34 @@ def test_unknown_user_code_error(self, mock_traceback_format_tb):
106178
107179 mock_traceback_format_tb .return_value = self .GENERIC_USER_ERROR_STACKTRACE
108180 self .assertEqual (
109- whom_to_blame (exception , self .EXECUTOR_MODULE , data_job_path ),
110181 errors .ResolvableBy .USER_ERROR ,
182+ whom_to_blame (exception , self .EXECUTOR_MODULE , data_job_path ),
111183 )
112184
185+ # TODO: https://github.com/vmware/versatile-data-kit/issues/2620
186+ # Test error for user-provided iterator
187+ # @patch(f"{traceback.format_tb.__module__}.{traceback.format_tb.__name__}")
188+ # def test_error_user_provided_iterator(self, mock_traceback_format_tb):
189+ # exception = Exception("User Error")
190+ #
191+ # mock_traceback_format_tb.return_value = self.USER_ERROR_USER_PROVIDED_ITERATOR
192+ # self.assertEqual(
193+ # errors.ResolvableBy.USER_ERROR,
194+ # whom_to_blame(exception, self.EXECUTOR_MODULE),
195+ # )
196+
197+ # TODO: https://github.com/vmware/versatile-data-kit/issues/2620
198+ # Test error for user-provided iterator that uses external library
199+ # @patch(f"{traceback.format_tb.__module__}.{traceback.format_tb.__name__}")
200+ # def test_error_user_provided_iterator_external_library(self, mock_traceback_format_tb):
201+ # exception = Exception("User Error")
202+ #
203+ # mock_traceback_format_tb.return_value = self.USER_ERROR_USER_PROVIDED_ITERATOR_EXTERNAL_LIBRARY
204+ # self.assertEqual(
205+ # errors.ResolvableBy.USER_ERROR,
206+ # whom_to_blame(exception, self.EXECUTOR_MODULE),
207+ # )
208+
113209 # Test errors in user code that cannot be recognised by VDK due to lack of valid job_path.
114210 @patch (f"{ traceback .format_tb .__module__ } .{ traceback .format_tb .__name__ } " )
115211 def test_unknown_user_code_error_with_none_job_path (self , mock_traceback_format_tb ):
@@ -118,8 +214,19 @@ def test_unknown_user_code_error_with_none_job_path(self, mock_traceback_format_
118214
119215 mock_traceback_format_tb .return_value = self .GENERIC_USER_ERROR_STACKTRACE
120216 self .assertEqual (
217+ errors .ResolvableBy .PLATFORM_ERROR ,
121218 whom_to_blame (exception , self .EXECUTOR_MODULE , data_job_path ),
219+ )
220+
221+ # Test errors thrown from external libraries used by vdk internal components
222+ @patch (f"{ traceback .format_tb .__module__ } .{ traceback .format_tb .__name__ } " )
223+ def test_error_thrown_in_external_library (self , mock_traceback_format_tb ):
224+ exception = Exception ("Should be Platform Error" )
225+ print (self .EXECUTOR_MODULE )
226+ mock_traceback_format_tb .return_value = self .PLATFORM_ERROR_EXTERNAL_LIBRARY
227+ self .assertEqual (
122228 errors .ResolvableBy .PLATFORM_ERROR ,
229+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
123230 )
124231
125232 # Generic error thrown by job_input that is not specifically recognised by VDK should be VAC error.
@@ -132,8 +239,8 @@ def test_job_input_generic_error(
132239 mock_is_user_error .return_value = False
133240 mock_traceback_format_tb .return_value = self .PLATFORM_ERROR_STACKTRACE
134241 self .assertEqual (
135- whom_to_blame (exception , self .EXECUTOR_MODULE ),
136242 errors .ResolvableBy .PLATFORM_ERROR ,
243+ whom_to_blame (exception , self .EXECUTOR_MODULE ),
137244 )
138245
139246
0 commit comments