Skip to content
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

Merged
merged 11 commits into from
Jul 19, 2021

Conversation

dhivyaganesan
Copy link
Contributor

  • New function in textutil class to format exception message.

  • All the traceback now uses traceback.format_exc()

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made

Quality of Code and Contribution Guidelines

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #2305 (e2eb2bc) into develop (f6e384e) will increase coverage by 0.03%.
The diff coverage is 68.18%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
azurelinuxagent/common/event.py 85.22% <ø> (ø)
azurelinuxagent/ga/exthandlers.py 86.16% <22.22%> (+0.22%) ⬆️
azurelinuxagent/agent.py 58.20% <50.00%> (-0.17%) ⬇️
azurelinuxagent/common/persist_firewall_rules.py 76.92% <50.00%> (-0.14%) ⬇️
azurelinuxagent/common/protocol/wire.py 78.75% <50.00%> (-0.03%) ⬇️
azurelinuxagent/common/utils/textutil.py 62.50% <63.63%> (+0.05%) ⬆️
azurelinuxagent/common/utils/restutil.py 85.04% <100.00%> (-0.05%) ⬇️
azurelinuxagent/daemon/main.py 70.00% <100.00%> (ø)
azurelinuxagent/ga/collect_telemetry_events.py 91.43% <100.00%> (+1.71%) ⬆️
azurelinuxagent/ga/remoteaccess.py 89.47% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f6e384e...e2eb2bc. Read the comment docs.

@@ -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()))
Copy link
Member

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.

Copy link
Contributor

@kevinclark19a kevinclark19a left a 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
Copy link
Member

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(
Copy link
Member

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,
Copy link
Member

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

@@ -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))
Copy link
Member

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))
Copy link
Member

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove \n

@dhivyaganesan dhivyaganesan merged commit f6699cd into Azure:develop Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants