55
55
}
56
56
57
57
58
- def _error_result_to_exception (error_result ):
58
+ def _error_result_to_exception (error_result , errors = None ):
59
59
"""Maps BigQuery error reasons to an exception.
60
60
61
61
The reasons and their matching HTTP status codes are documented on
@@ -66,6 +66,7 @@ def _error_result_to_exception(error_result):
66
66
67
67
Args:
68
68
error_result (Mapping[str, str]): The error result from BigQuery.
69
+ errors (Union[Iterable[str], None]): The detailed error messages.
69
70
70
71
Returns:
71
72
google.cloud.exceptions.GoogleAPICallError: The mapped exception.
@@ -74,8 +75,24 @@ def _error_result_to_exception(error_result):
74
75
status_code = _ERROR_REASON_TO_EXCEPTION .get (
75
76
reason , http .client .INTERNAL_SERVER_ERROR
76
77
)
78
+ # Manually create error message to preserve both error_result and errors.
79
+ # Can be removed once b/310544564 and b/318889899 are resolved.
80
+ concatenated_errors = ""
81
+ if errors :
82
+ concatenated_errors = "; "
83
+ for err in errors :
84
+ concatenated_errors += ", " .join (
85
+ [f"{ key } : { value } " for key , value in err .items ()]
86
+ )
87
+ concatenated_errors += "; "
88
+
89
+ # strips off the last unneeded semicolon and space
90
+ concatenated_errors = concatenated_errors [:- 2 ]
91
+
92
+ error_message = error_result .get ("message" , "" ) + concatenated_errors
93
+
77
94
return exceptions .from_http_status (
78
- status_code , error_result . get ( "message" , "" ) , errors = [error_result ]
95
+ status_code , error_message , errors = [error_result ]
79
96
)
80
97
81
98
@@ -886,7 +903,9 @@ def _set_future_result(self):
886
903
return
887
904
888
905
if self .error_result is not None :
889
- exception = _error_result_to_exception (self .error_result )
906
+ exception = _error_result_to_exception (
907
+ self .error_result , self .errors or ()
908
+ )
890
909
self .set_exception (exception )
891
910
else :
892
911
self .set_result (self )
0 commit comments