Skip to content

Commit 8ea30e2

Browse files
committed
logging output update
1 parent 47e2ba1 commit 8ea30e2

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='stackql-deploy',
13-
version='1.8.6',
13+
version='1.8.7',
1414
description='Model driven resource provisioning and deployment framework using StackQL.',
1515
long_description=readme,
1616
long_description_content_type='text/x-rst',

stackql_deploy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.8.6'
1+
__version__ = '1.8.7'

stackql_deploy/cmd/base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ def process_exports(
119119
show_query(True, exports_query, self.logger)
120120
catch_error_and_exit(f"exports query failed for {resource['name']}", self.logger)
121121

122+
# Check if we received an error from the query execution
123+
if (len(exports) >= 1 and isinstance(exports[0], dict)):
124+
# Check for our custom error wrapper
125+
if '_stackql_deploy_error' in exports[0]:
126+
error_msg = exports[0]['_stackql_deploy_error']
127+
show_query(True, exports_query, self.logger)
128+
catch_error_and_exit(
129+
f"exports query failed for {resource['name']}\n\nError details:\n{error_msg}",
130+
self.logger
131+
)
132+
# Check for direct error in result
133+
elif 'error' in exports[0]:
134+
error_msg = exports[0]['error']
135+
show_query(True, exports_query, self.logger)
136+
catch_error_and_exit(
137+
f"exports query failed for {resource['name']}\n\nError details:\n{error_msg}",
138+
self.logger
139+
)
140+
122141
if len(exports) > 1:
123142
catch_error_and_exit(
124143
f"exports should include one row only, received {str(len(exports))} rows",

stackql_deploy/lib/utils.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def get_type(resource, logger):
3939

4040
def 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

Comments
 (0)