-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helper to handle exception message #2305
Helper to handle exception message #2305
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2305 +/- ##
===========================================
+ Coverage 70.69% 70.72% +0.03%
===========================================
Files 96 96
Lines 13953 13952 -1
Branches 2001 2001
===========================================
+ Hits 9864 9868 +4
+ Misses 3648 3645 -3
+ Partials 441 439 -2
Continue to review full report at Codecov.
|
azurelinuxagent/common/event.py
Outdated
@@ -320,7 +320,7 @@ def report_dropped_events_error(count, errors, operation_name): | |||
def _update_errors_and_get_count(error_count, errors, error): | |||
error_count += 1 | |||
if len(errors) < CollectOrReportEventDebugInfo.__MAX_ERRORS_TO_REPORT: | |||
errors.add("{0}: {1}".format(ustr(error), traceback.format_exc())) | |||
errors.add("{0}: {1}".format(ustr(error), textutil.format_exception())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think textutil.format_exception should take the exception as parameter, otherwise we have an (implicit) requirement that is must be called within an exception handler and in some case, as this one, that is not clear/enforced in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good. Would like to see the exception be parameterized like @narrieta said, but I'm fine other than that.
|
||
|
||
def format_exception(exception): | ||
# Placeholder function to format exception message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: remove "Placeholder" from comment
@@ -116,8 +116,8 @@ def _operation(self): | |||
# the telemetry service comes back up | |||
delete_all_event_files = False | |||
except Exception as error: | |||
msg = "Unknown error occurred when trying to collect extension events. Error: {0}, Stack: {1}".format( | |||
ustr(error), traceback.format_exc()) | |||
msg = "Unknown error occurred when trying to collect extension events.:\n{0}".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"...extension events: {0}" (remove '.' and '\n')
@@ -204,8 +204,8 @@ def _capture_extension_events(self, handler_name, handler_event_dir_path): | |||
# This is a trade-off between data replication vs data loss. | |||
raise | |||
except Exception as error: | |||
msg = "Failed to process event file {0}: {1}, {2}".format(event_file, ustr(error), | |||
traceback.format_exc()) | |||
msg = "Failed to process event file {0}: \n, {1}".format(event_file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need these extra \n. The message should display on the same line. as in the previous code.
@@ -135,8 +135,8 @@ def _process_telemetry_thread(self): | |||
self._send_events_in_queue(first_event) | |||
|
|||
except Exception as error: | |||
err_msg = "An unknown error occurred in the {0} thread main loop, stopping thread. Error: {1}, Stack: {2}".format( | |||
self.get_thread_name(), ustr(error), traceback.format_exc()) | |||
err_msg = "An unknown error occurred in the {0} thread main loop, stopping thread.\n {1}".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n
azurelinuxagent/ga/exthandlers.py
Outdated
@@ -351,7 +342,7 @@ def goal_state_debug_info(duration=None): | |||
self.__process_and_handle_extensions(etag) | |||
self._cleanup_outdated_handlers() | |||
except Exception as error: | |||
error = u"ProcessExtensionsInGoalState - Exception processing extension handlers: {0}\n{1}".format(ustr(error), traceback.extract_tb(get_traceback(error))) | |||
error = u"ProcessExtensionsInGoalState - Exception processing extension handlers:\n {0}".format(textutil.format_exception(error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n
@@ -1207,7 +1206,7 @@ def _send_event(provider_id, debug_info): | |||
events_per_provider[event.providerId] += 1 | |||
|
|||
except Exception as error: | |||
logger.warn("Unexpected error when generating Events: {0}, {1}", ustr(error), traceback.format_exc()) | |||
logger.warn("Unexpected error when generating Events:\n {0}", textutil.format_exception(error)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove \n
@@ -808,7 +807,7 @@ def try_update_goal_state(self): | |||
self._last_try_update_goal_state_failed = True | |||
message = u"An error occurred while retrieving the goal state: {0}".format(ustr(e)) | |||
add_event(AGENT_NAME, op=WALAEventOperation.FetchGoalState, version=CURRENT_VERSION, is_success=False, message=message, log_event=False) | |||
message = u"An error occurred while retrieving the goal state: {0}".format(ustr(traceback.format_exc())) | |||
message = u"An error occurred while retrieving the goal state:\n {0}".format(textutil.format_exception(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove \n
New function in textutil class to format exception message.
All the traceback now uses traceback.format_exc()
Issue #
PR information
Quality of Code and Contribution Guidelines