6
6
7
7
import pytest
8
8
from dagster import Config , RunConfig , config_mapping , job , op
9
+ from dagster ._core .definitions .events import Failure
9
10
from dagster ._core .definitions .timestamp import TimestampWithTimezone
10
11
from dagster ._core .errors import (
12
+ DagsterExecutionInterruptedError ,
11
13
DagsterUserCodeExecutionError ,
12
14
DagsterUserCodeProcessError ,
13
15
user_code_error_boundary ,
@@ -84,34 +86,6 @@ def hunter2():
84
86
assert "hunter2" not in str (err_info )
85
87
86
88
87
- def test_masking_nested_user_code_err_reraise (enable_masking_user_code_errors ):
88
- class MyException (Exception ):
89
- inner : Exception
90
-
91
- def __init__ (self , inner : Exception ):
92
- self .inner = inner
93
-
94
- try :
95
- try :
96
- with user_code_error_boundary (
97
- error_cls = DagsterUserCodeExecutionError ,
98
- msg_fn = lambda : "test" ,
99
- ):
100
-
101
- def hunter2 ():
102
- raise UserError ()
103
-
104
- hunter2 ()
105
- except Exception as e :
106
- raise MyException (e ) from e
107
-
108
- except Exception :
109
- exc_info = sys .exc_info ()
110
- err_info = serializable_error_info_from_exc_info (exc_info )
111
-
112
- assert "hunter2" not in str (err_info )
113
-
114
-
115
89
def test_masking_nested_user_code_err_boundaries_reraise (enable_masking_user_code_errors ):
116
90
try :
117
91
try :
@@ -140,12 +114,20 @@ def hunter2():
140
114
141
115
142
116
@pytest .mark .parametrize (
143
- "build_exc" ,
144
- [lambda : UserError (), lambda : KeyboardInterrupt ("hunter2" ), lambda : hunter2 () - 5 ], # type:ignore
145
- ids = ["UserError" , "KeyboardInterrupt" , "TypeError" ],
117
+ "exc_name, expect_exc_name_in_error, build_exc" ,
118
+ [
119
+ ("UserError" , False , lambda : UserError ()),
120
+ ("TypeError" , False , lambda : TypeError ("hunter2" )),
121
+ ("KeyboardInterrupt" , True , lambda : KeyboardInterrupt ()),
122
+ ("DagsterExecutionInterruptedError" , True , lambda : DagsterExecutionInterruptedError ()),
123
+ ("Failure" , True , lambda : Failure ("asdf" )),
124
+ ],
146
125
)
147
126
def test_masking_op_execution (
148
- enable_masking_user_code_errors , build_exc : Callable [[], BaseException ]
127
+ enable_masking_user_code_errors ,
128
+ exc_name : str ,
129
+ expect_exc_name_in_error : bool ,
130
+ build_exc : Callable [[], BaseException ],
149
131
) -> Any :
150
132
@op
151
133
def throws_user_error (_ ):
@@ -167,10 +149,17 @@ def job_def():
167
149
]
168
150
169
151
step_error = next (event for event in result .all_events if event .is_step_failure )
170
- assert (
171
- step_error .step_failure_data .error
172
- and step_error .step_failure_data .error .cls_name == "DagsterRedactedUserCodeError"
173
- )
152
+
153
+ if expect_exc_name_in_error :
154
+ assert (
155
+ step_error .step_failure_data .error
156
+ and step_error .step_failure_data .error .cls_name == exc_name
157
+ )
158
+ else :
159
+ assert (
160
+ step_error .step_failure_data .error
161
+ and step_error .step_failure_data .error .cls_name == "DagsterRedactedUserCodeError"
162
+ )
174
163
175
164
176
165
ERROR_ID_REGEX = r"Error occurred during user code execution, error ID ([a-z0-9\-]+)"
0 commit comments