5555}
5656
5757
58- def _error_result_to_exception (error_result ):
58+ def _error_result_to_exception (error_result , errors = None ):
5959 """Maps BigQuery error reasons to an exception.
6060
6161 The reasons and their matching HTTP status codes are documented on
@@ -66,6 +66,7 @@ def _error_result_to_exception(error_result):
6666
6767 Args:
6868 error_result (Mapping[str, str]): The error result from BigQuery.
69+ errors (Union[Iterable[str], None]): The detailed error messages.
6970
7071 Returns:
7172 google.cloud.exceptions.GoogleAPICallError: The mapped exception.
@@ -74,8 +75,24 @@ def _error_result_to_exception(error_result):
7475 status_code = _ERROR_REASON_TO_EXCEPTION .get (
7576 reason , http .client .INTERNAL_SERVER_ERROR
7677 )
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+
7794 return exceptions .from_http_status (
78- status_code , error_result . get ( "message" , "" ) , errors = [error_result ]
95+ status_code , error_message , errors = [error_result ]
7996 )
8097
8198
@@ -886,7 +903,9 @@ def _set_future_result(self):
886903 return
887904
888905 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+ )
890909 self .set_exception (exception )
891910 else :
892911 self .set_result (self )
0 commit comments