Skip to content

Commit

Permalink
chore: Edit logger.error calls (#1019)
Browse files Browse the repository at this point in the history
* Edit logger.errors that don't need to be called as errors to warning or debug
  • Loading branch information
lev-i authored Jun 30, 2022
1 parent 268d4b3 commit 2cbbed5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions azure-iot-device/azure/iot/device/common/handle_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def handle_background_exception(e):

# @FUTURE: We should add a mechanism which allows applications to receive these
# exceptions so they can respond accordingly
logger.error(msg="Exception caught in background thread. Unable to handle.")
logger.error(traceback.format_exception_only(type(e), e))
logger.warning(msg="Exception caught in background thread. Unable to handle.")
logger.warning(traceback.format_exception_only(type(e), e))


def swallow_unraised_exception(e, log_msg=None, log_lvl="warning"):
Expand Down
38 changes: 20 additions & 18 deletions azure-iot-device/azure/iot/device/common/mqtt_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,22 @@ def on_connect(client, userdata, flags, rc):
_create_error_from_connack_rc_code(rc)
)
except Exception:
logger.error("Unexpected error calling on_mqtt_connection_failure_handler")
logger.error(traceback.format_exc())
logger.warning(
"Unexpected error calling on_mqtt_connection_failure_handler"
)
logger.warning(traceback.format_exc())
else:
logger.error(
logger.warning(
"connection failed, but no on_mqtt_connection_failure_handler handler callback provided"
)
elif this.on_mqtt_connected_handler:
try:
this.on_mqtt_connected_handler()
except Exception:
logger.error("Unexpected error calling on_mqtt_connected_handler")
logger.error(traceback.format_exc())
logger.warning("Unexpected error calling on_mqtt_connected_handler")
logger.warning(traceback.format_exc())
else:
logger.error("No event handler callback set for on_mqtt_connected_handler")
logger.debug("No event handler callback set for on_mqtt_connected_handler")

def on_disconnect(client, userdata, rc):
this = self_weakref()
Expand All @@ -220,10 +222,10 @@ def on_disconnect(client, userdata, rc):
try:
this.on_mqtt_disconnected_handler(cause)
except Exception:
logger.error("Unexpected error calling on_mqtt_disconnected_handler")
logger.error(traceback.format_exc())
logger.warning("Unexpected error calling on_mqtt_disconnected_handler")
logger.warning(traceback.format_exc())
else:
logger.error("No event handler callback set for on_mqtt_disconnected_handler")
logger.warning("No event handler callback set for on_mqtt_disconnected_handler")

def on_subscribe(client, userdata, mid, granted_qos):
this = self_weakref()
Expand Down Expand Up @@ -254,10 +256,10 @@ def on_message(client, userdata, mqtt_message):
try:
this.on_mqtt_message_received_handler(mqtt_message.topic, mqtt_message.payload)
except Exception:
logger.error("Unexpected error calling on_mqtt_message_received_handler")
logger.error(traceback.format_exc())
logger.warning("Unexpected error calling on_mqtt_message_received_handler")
logger.warning(traceback.format_exc())
else:
logger.error(
logger.debug(
"No event handler callback set for on_mqtt_message_received_handler - DROPPING MESSAGE"
)

Expand Down Expand Up @@ -601,8 +603,8 @@ def establish_operation(self, mid, callback=None):
try:
callback()
except Exception:
logger.error("Unexpected error calling callback for MID: {}".format(mid))
logger.error(traceback.format_exc())
logger.debug("Unexpected error calling callback for MID: {}".format(mid))
logger.debug(traceback.format_exc())
else:
# Not entirely unexpected because of QOS=1
logger.debug("No callback for MID: {}".format(mid))
Expand Down Expand Up @@ -644,8 +646,8 @@ def complete_operation(self, mid):
try:
callback()
except Exception:
logger.error("Unexpected error calling callback for MID: {}".format(mid))
logger.error(traceback.format_exc())
logger.debug("Unexpected error calling callback for MID: {}".format(mid))
logger.debug(traceback.format_exc())
else:
# fully expected. QOS=1 means we might get 2 PUBACKs
logger.debug("No callback set for MID: {}".format(mid))
Expand Down Expand Up @@ -674,7 +676,7 @@ def cancel_all_operations(self):
try:
callback(cancelled=True)
except Exception:
logger.error("Unexpected error calling callback for MID: {}".format(mid))
logger.error(traceback.format_exc())
logger.debug("Unexpected error calling callback for MID: {}".format(mid))
logger.debug(traceback.format_exc())
else:
logger.debug("Cancelling {} - No callback set for MID".format(mid))
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ def handle_pipeline_event(self, event):
except Exception as e:
# Do not use exc_info parameter on logger.* calls. This causes pytest to save the
# traceback which saves stack frames which shows up as a leak
logger.error(
logger.warning(
msg="{}: Unexpected error in ._handle_pipeline_event() call: {}".format(self, e)
)
if self.previous:
logger.error("{}: Raising background exception")
logger.warning("{}: Raising background exception")
self.report_background_exception(e)
else:
# Nothing else we can do but log this. There exists no stage we can send the
# exception to, and raising would send the error back down the pipeline.
logger.error(
logger.warning(
"{}: Cannot report a background exception because there is no previous stage!"
)

Expand Down Expand Up @@ -187,7 +187,7 @@ def send_op_down(self, op):
self.next.run_op(op)
else:
# This shouldn't happen if the pipeline was created correctly
logger.error(
logger.warning(
"{}({}): no next stage.cannot send op down. completing with error".format(
self.name, op.name
)
Expand Down Expand Up @@ -344,7 +344,7 @@ def _handle_pipeline_event(self, event):
)
else:
# unexpected condition: we should be handling all pipeline events
logger.error("incoming {} event with no handler. dropping.".format(event.name))
logger.debug("incoming {} event with no handler. dropping.".format(event.name))


# NOTE: This stage could be a candidate for being refactored into some kind of other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ def _on_pipeline_event(event):
if self.on_c2d_message_received:
self.on_c2d_message_received(event.message)
else:
logger.error("C2D message event received with no handler. dropping.")
logger.debug("C2D message event received with no handler. dropping.")

elif isinstance(event, pipeline_events_iothub.InputMessageEvent):
if self.on_input_message_received:
self.on_input_message_received(event.message)
else:
logger.error("input message event received with no handler. dropping.")
logger.debug("input message event received with no handler. dropping.")

elif isinstance(event, pipeline_events_iothub.MethodRequestEvent):
if self.on_method_request_received:
self.on_method_request_received(event.method_request)
else:
logger.error("Method request event received with no handler. Dropping.")
logger.debug("Method request event received with no handler. Dropping.")

elif isinstance(event, pipeline_events_iothub.TwinDesiredPropertiesPatchEvent):
if self.on_twin_patch_received:
self.on_twin_patch_received(event.patch)
else:
logger.error("Twin patch event received with no handler. Dropping.")
logger.debug("Twin patch event received with no handler. Dropping.")

else:
logger.error("Dropping unknown pipeline event {}".format(event.name))
logger.debug("Dropping unknown pipeline event {}".format(event.name))

def _on_connected():
if self.on_connected:
Expand Down Expand Up @@ -515,7 +515,9 @@ def enable_feature(self, feature_name, callback):

def on_complete(op, error):
if error:
logger.error("Subscribe for {} failed. Not enabling feature".format(feature_name))
logger.warning(
"Subscribe for {} failed. Not enabling feature".format(feature_name)
)
else:
self.feature_enabled[feature_name] = True
callback(error=error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _get_feature_subscription_topic(self, feature):
elif feature == pipeline_constant.TWIN_PATCHES:
return mqtt_topic_iothub.get_twin_patch_topic_for_subscribe()
else:
logger.error("Cannot retrieve MQTT topic for subscription to invalid feature")
logger.warning("Cannot retrieve MQTT topic for subscription to invalid feature")
raise pipeline_exceptions.OperationError(
"Trying to enable/disable invalid feature - {}".format(feature)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, pipeline_configuration):

def _on_pipeline_event(event):
# error because no events should
logger.error("Dropping unknown pipeline event {}".format(event.name))
logger.debug("Dropping unknown pipeline event {}".format(event.name))

def _on_connected():
if self.on_connected:
Expand Down

0 comments on commit 2cbbed5

Please sign in to comment.