@@ -1001,9 +1001,20 @@ def t1(a: typing.List[int]) -> typing.List[typing.List[str]]:
1001
1001
@mock .patch ("flytekit.core.data_persistence.FileAccessProvider.put_data" )
1002
1002
@mock .patch ("flytekit.core.utils.write_proto_to_file" )
1003
1003
def test_dispatch_execute_custom_error_code_with_flyte_user_runtime_exception (mock_write_to_file , mock_upload_dir , mock_get_data , mock_load_proto ):
1004
- class CustomException (FlyteUserRuntimeException ):
1004
+ class CustomException (Exception ):
1005
1005
_ERROR_CODE = "CUSTOM_ERROR_CODE"
1006
1006
1007
+ @property
1008
+ def error_code (self ):
1009
+ return self ._ERROR_CODE
1010
+
1011
+ # Mimic real logic - executes and wraps any exception in a FlyteUserRuntimeException
1012
+ def fake_dispatch_execute (* args , ** kwargs ):
1013
+ try :
1014
+ return python_task .execute (** kwargs )
1015
+ except Exception as e :
1016
+ raise FlyteUserRuntimeException (e ) from e
1017
+
1007
1018
mock_get_data .return_value = True
1008
1019
mock_upload_dir .return_value = True
1009
1020
@@ -1014,14 +1025,16 @@ class CustomException(FlyteUserRuntimeException):
1014
1025
)
1015
1026
) as ctx :
1016
1027
python_task = mock .MagicMock ()
1017
- python_task .dispatch_execute .side_effect = CustomException ("custom error" )
1028
+ python_task .execute .side_effect = CustomException ("custom error" )
1029
+ python_task .dispatch_execute .side_effect = fake_dispatch_execute
1018
1030
1019
1031
empty_literal_map = _literal_models .LiteralMap ({}).to_flyte_idl ()
1020
1032
mock_load_proto .return_value = empty_literal_map
1021
1033
1022
1034
def verify_output (* args , ** kwargs ):
1023
- assert isinstance (args [0 ], ErrorDocument )
1024
- assert args [0 ].error .code == "CUSTOM_ERROR_CODE"
1035
+ error_document = args [0 ]
1036
+ assert isinstance (error_document , ErrorDocument )
1037
+ assert error_document .error .code == "CUSTOM_ERROR_CODE"
1025
1038
1026
1039
mock_write_to_file .side_effect = verify_output
1027
1040
_dispatch_execute (ctx , lambda : python_task , "inputs path" , "outputs prefix" )
0 commit comments