@@ -307,15 +307,24 @@ async def non_serializable_output(
307
307
308
308
@dataclass
309
309
class Failure :
310
+ """A Nexus Failure object, with details parsed into an exception.
311
+
312
+ https://github.com/nexus-rpc/api/blob/main/SPEC.md#failure
313
+ """
314
+
310
315
message : str = ""
311
316
metadata : Optional [dict [str , str ]] = None
312
317
details : Optional [dict [str , Any ]] = None
313
318
314
- exception : Optional [BaseException ] = dataclasses .field (init = False , default = None )
319
+ exception_from_details : Optional [BaseException ] = dataclasses .field (
320
+ init = False , default = None
321
+ )
315
322
316
323
def __post_init__ (self ) -> None :
317
324
if self .metadata and (error_type := self .metadata .get ("type" )):
318
- self .exception = self ._instantiate_exception (error_type , self .details )
325
+ self .exception_from_details = self ._instantiate_exception (
326
+ error_type , self .details
327
+ )
319
328
320
329
def _instantiate_exception (
321
330
self , error_type : str , details : Optional [dict [str , Any ]]
@@ -420,9 +429,9 @@ def check_response(
420
429
else :
421
430
assert cls .expected .retryable_header is None
422
431
423
- if failure .exception :
424
- assert isinstance (failure .exception , ApplicationError )
425
- assert failure .exception .non_retryable == (
432
+ if failure .exception_from_details :
433
+ assert isinstance (failure .exception_from_details , ApplicationError )
434
+ assert failure .exception_from_details .non_retryable == (
426
435
not cls .expected .retryable_exception
427
436
)
428
437
else :
@@ -607,7 +616,7 @@ def check_response(
607
616
) -> None :
608
617
super ().check_response (response , with_service_definition )
609
618
failure = Failure (** response .json ())
610
- err = failure .exception
619
+ err = failure .exception_from_details
611
620
assert isinstance (err , ApplicationError )
612
621
assert err .non_retryable
613
622
assert err .type == "TestFailureType"
0 commit comments