66
66
67
67
68
68
_CONTAINS_ORDER_BY = re .compile (r"ORDER\s+BY" , re .IGNORECASE )
69
+ _EXCEPTION_FOOTER_TEMPLATE = "{message}\n \n Location: {location}\n Job ID: {job_id}\n "
69
70
_TIMEOUT_BUFFER_SECS = 0.1
70
71
71
72
@@ -1196,17 +1197,17 @@ def _blocking_poll(self, timeout=None, **kwargs):
1196
1197
super (QueryJob , self )._blocking_poll (timeout = timeout , ** kwargs )
1197
1198
1198
1199
@staticmethod
1199
- def _format_for_exception (query , job_id ):
1200
+ def _format_for_exception (message : str , query : str ):
1200
1201
"""Format a query for the output in exception message.
1201
1202
1202
1203
Args:
1204
+ message (str): The original exception message.
1203
1205
query (str): The SQL query to format.
1204
- job_id (str): The ID of the job that ran the query.
1205
1206
1206
1207
Returns:
1207
1208
str: A formatted query text.
1208
1209
"""
1209
- template = "\n \n (job ID: {job_id}) \n \n {header}\n \n {ruler}\n {body}\n {ruler}"
1210
+ template = "{message} \n \n {header}\n \n {ruler}\n {body}\n {ruler}"
1210
1211
1211
1212
lines = query .splitlines ()
1212
1213
max_line_len = max (len (line ) for line in lines )
@@ -1223,7 +1224,7 @@ def _format_for_exception(query, job_id):
1223
1224
"{:4}:{}" .format (n , line ) for n , line in enumerate (lines , start = 1 )
1224
1225
)
1225
1226
1226
- return template .format (job_id = job_id , header = header , ruler = ruler , body = body )
1227
+ return template .format (message = message , header = header , ruler = ruler , body = body )
1227
1228
1228
1229
def _begin (self , client = None , retry = DEFAULT_RETRY , timeout = None ):
1229
1230
"""API call: begin the job via a POST request
@@ -1248,7 +1249,10 @@ def _begin(self, client=None, retry=DEFAULT_RETRY, timeout=None):
1248
1249
try :
1249
1250
super (QueryJob , self )._begin (client = client , retry = retry , timeout = timeout )
1250
1251
except exceptions .GoogleAPICallError as exc :
1251
- exc .message += self ._format_for_exception (self .query , self .job_id )
1252
+ exc .message = _EXCEPTION_FOOTER_TEMPLATE .format (
1253
+ message = exc .message , location = self .location , job_id = self .job_id
1254
+ )
1255
+ exc .debug_message = self ._format_for_exception (exc .message , self .query )
1252
1256
exc .query_job = self
1253
1257
raise
1254
1258
@@ -1447,7 +1451,10 @@ def do_get_result():
1447
1451
do_get_result ()
1448
1452
1449
1453
except exceptions .GoogleAPICallError as exc :
1450
- exc .message += self ._format_for_exception (self .query , self .job_id )
1454
+ exc .message = _EXCEPTION_FOOTER_TEMPLATE .format (
1455
+ message = exc .message , location = self .location , job_id = self .job_id
1456
+ )
1457
+ exc .debug_message = self ._format_for_exception (exc .message , self .query ) # type: ignore
1451
1458
exc .query_job = self # type: ignore
1452
1459
raise
1453
1460
except requests .exceptions .Timeout as exc :
0 commit comments