@@ -39,6 +39,7 @@ def get_type(resource, logger):
3939
4040def run_stackql_query (query , stackql , suppress_errors , logger , custom_auth = None , env_vars = None , retries = 0 , delay = 5 ):
4141 attempt = 0
42+ last_error = None
4243 while attempt <= retries :
4344 try :
4445 logger .debug (f"(utils.run_stackql_query) executing stackql query on attempt { attempt + 1 } :\n \n { query } \n " )
@@ -50,20 +51,22 @@ def run_stackql_query(query, stackql, suppress_errors, logger, custom_auth=None,
5051 if len (result ) == 0 :
5152 logger .debug ("(utils.run_stackql_query) stackql query executed successfully, retrieved 0 items." )
5253 pass
53- elif not suppress_errors and result and 'error' in result [0 ]:
54+ elif result and 'error' in result [0 ]:
5455 error_message = result [0 ]['error' ]
55- if attempt == retries :
56- # If retries are exhausted, log the error and exit
57- catch_error_and_exit (
58- (
59- f"(utils.run_stackql_query) error occurred during stackql query execution:\n \n "
60- f"{ error_message } \n "
61- ),
62- logger
63- )
64- else :
65- # Log the error and prepare for another attempt
66- logger .error (f"attempt { attempt + 1 } failed:\n \n { error_message } \n " )
56+ last_error = error_message # Store the error for potential return
57+ if not suppress_errors :
58+ if attempt == retries :
59+ # If retries are exhausted, log the error and exit
60+ catch_error_and_exit (
61+ (
62+ f"(utils.run_stackql_query) error occurred during stackql query execution:\n \n "
63+ f"{ error_message } \n "
64+ ),
65+ logger
66+ )
67+ else :
68+ # Log the error and prepare for another attempt
69+ logger .error (f"attempt { attempt + 1 } failed:\n \n { error_message } \n " )
6770 elif 'count' in result [0 ]:
6871 # If the result is a count query, return the count
6972 logger .debug (
@@ -95,6 +98,7 @@ def run_stackql_query(query, stackql, suppress_errors, logger, custom_auth=None,
9598
9699 except Exception as e :
97100 # Log the exception and check if retry attempts are exhausted
101+ last_error = str (e ) # Store the exception for potential return
98102 if attempt == retries :
99103 catch_error_and_exit (
100104 f"(utils.run_stackql_query) an exception occurred during stackql query execution:\n \n { str (e )} \n " ,
@@ -108,6 +112,9 @@ def run_stackql_query(query, stackql, suppress_errors, logger, custom_auth=None,
108112 attempt += 1
109113
110114 logger .debug (f"(utils.run_stackql_query) all attempts ({ retries + 1 } ) to execute the query completed." )
115+ # If suppress_errors is True and we have an error, return an empty list with error info as a special dict
116+ if suppress_errors and last_error :
117+ return [{'_stackql_deploy_error' : last_error }]
111118 # return None
112119 return []
113120
0 commit comments