@@ -88,8 +88,10 @@ def start(self, cluster_id: str) -> None:
8888
8989 response = self .session .post ("/start" , json = {"cluster_id" : cluster_id })
9090 if response .status_code != 200 :
91- raise DbtRuntimeError (f"Error starting terminated cluster.\n { response .content !r} " )
92- logger .debug (f"Cluster start response={ response } " )
91+ if self .status (cluster_id ) not in ["RUNNING" , "PENDING" ]:
92+ raise DbtRuntimeError (f"Error starting terminated cluster.\n { response .content !r} " )
93+ else :
94+ logger .debug ("Presuming race condition, waiting for cluster to start" )
9395
9496 self .wait_for_cluster (cluster_id )
9597
@@ -289,7 +291,7 @@ def cancel(self, command: CommandExecution) -> None:
289291 raise DbtRuntimeError (f"Cancel command { command } failed.\n { response .content !r} " )
290292
291293 def poll_for_completion (self , command : CommandExecution ) -> None :
292- self ._poll_api (
294+ response = self ._poll_api (
293295 url = "/status" ,
294296 params = {
295297 "clusterId" : command .cluster_id ,
@@ -300,7 +302,13 @@ def poll_for_completion(self, command: CommandExecution) -> None:
300302 terminal_states = {"Finished" , "Error" , "Cancelled" },
301303 expected_end_state = "Finished" ,
302304 unexpected_end_state_func = self ._get_exception ,
303- )
305+ ).json ()
306+
307+ if response ["results" ]["resultType" ] == "error" :
308+ raise DbtRuntimeError (
309+ f"Python model failed with traceback as:\n "
310+ f"{ utils .remove_ansi (response ['results' ]['cause' ])} "
311+ )
304312
305313 def _get_exception (self , response : Response ) -> None :
306314 response_json = response .json ()
0 commit comments