diff --git a/ansible_rulebook/cli.py b/ansible_rulebook/cli.py index 6df8aabe..f083d913 100644 --- a/ansible_rulebook/cli.py +++ b/ansible_rulebook/cli.py @@ -238,8 +238,8 @@ def main(args: List[str] = None) -> int: asyncio.run(app.run(args)) except KeyboardInterrupt: return 0 - except Exception: - logger.exception("Unexpected exception") + except Exception as err: + logger.error("Terminating %s", str(err)) return 1 return 0 diff --git a/ansible_rulebook/engine.py b/ansible_rulebook/engine.py index 0415544e..e2c22506 100644 --- a/ansible_rulebook/engine.py +++ b/ansible_rulebook/engine.py @@ -198,7 +198,7 @@ async def start_source( ) logger.info("Task cancelled " + shutdown_msg) except BaseException as e: - logger.exception("Source error") + logger.error("Source error %s", str(e)) shutdown_msg = ( f"Shutting down source: {source.source_name} error : {e}" ) diff --git a/ansible_rulebook/rule_set_runner.py b/ansible_rulebook/rule_set_runner.py index f96a86b7..0ee1ca4f 100644 --- a/ansible_rulebook/rule_set_runner.py +++ b/ansible_rulebook/rule_set_runner.py @@ -392,12 +392,16 @@ async def _call_action( **action_args, ) except KeyError as e: - logger.exception( - "KeyError with variables %s", pformat(variables_copy) + logger.error( + "KeyError %s with variables %s", + str(e), + pformat(variables_copy), ) result = dict(error=e) except MessageNotHandledException as e: - logger.exception("Message cannot be handled: %s", action_args) + logger.error( + "Message cannot be handled: %s err %s", action_args, str(e) + ) result = dict(error=e) except MessageObservedException as e: logger.info("MessageObservedException: %s", action_args) @@ -413,7 +417,7 @@ async def _call_action( logger.debug("Action task caught Cancelled error") raise except Exception as e: - logger.exception("Error calling %s", action) + logger.error("Error calling action %s, err %s", action, str(e)) result = dict(error=e) except BaseException as e: logger.error(e) diff --git a/ansible_rulebook/validators.py b/ansible_rulebook/validators.py index e13ea886..8d264d2d 100644 --- a/ansible_rulebook/validators.py +++ b/ansible_rulebook/validators.py @@ -31,11 +31,11 @@ def _get_schema(cls): cls.schema = json.loads(data) validator = jsonschema.validators.validator_for(cls.schema) validator.check_schema(cls.schema) - except json.JSONDecodeError: - logger.exception("Can not deserialize JSON schema") + except json.JSONDecodeError as err: + logger.error("Can not deserialize JSON schema: %s", str(err)) raise - except SchemaError: - logger.exception("Incorrect JSON schema") + except SchemaError as err: + logger.error("Incorrect JSON schema: %s", str(err)) raise return cls.schema @@ -43,6 +43,6 @@ def _get_schema(cls): def rulebook(cls, instance: List[Dict]) -> None: try: jsonschema.validate(instance=instance, schema=cls._get_schema()) - except ValidationError: - logger.exception("Rulebook failed validation.") + except ValidationError as err: + logger.error("Rulebook failed validation, err %s", str(err)) raise diff --git a/ansible_rulebook/websocket.py b/ansible_rulebook/websocket.py index 8f396ce3..68f06905 100644 --- a/ansible_rulebook/websocket.py +++ b/ansible_rulebook/websocket.py @@ -107,8 +107,8 @@ async def send_event_log_to_websocket( except CancelledError: logger.info("closing websocket due to task cancelled") return - except BaseException: - logger.exception("websocket error on %s", event) + except BaseException as err: + logger.error("websocket error on %s err: %s", event, str(err)) def _sslcontext(url, ssl_verify) -> ssl.SSLContext: