From 49726b8cec6351b0783e9b8bee7ad5f4b8b7cc30 Mon Sep 17 00:00:00 2001 From: Eriks Karls Date: Wed, 29 Apr 2020 10:53:38 +0300 Subject: [PATCH] __all__ list extended, created function for error catching and processing, error processing minor fix --- erepublik/__init__.py | 2 +- erepublik/utils.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/erepublik/__init__.py b/erepublik/__init__.py index 7b1d3b4..f2eb7f1 100644 --- a/erepublik/__init__.py +++ b/erepublik/__init__.py @@ -5,7 +5,7 @@ __author__ = """Eriks Karls""" __email__ = 'eriks@72.lv' __version__ = '0.20.0' -__commit_id__ = "904fd4e" +__commit_id__ = "9a0cbf7" from erepublik import classes, utils from erepublik.citizen import Citizen diff --git a/erepublik/utils.py b/erepublik/utils.py index 3266a85..bf3699b 100644 --- a/erepublik/utils.py +++ b/erepublik/utils.py @@ -25,7 +25,8 @@ __all__ = ["FOOD_ENERGY", "COMMIT_ID", "COUNTRIES", "erep_tz", 'COUNTRY_LINK', "now", "localize_dt", "localize_timestamp", "good_timedelta", "eday_from_date", "date_from_eday", "get_sleep_seconds", "interactive_sleep", "silent_sleep", "write_silent_log", "write_interactive_log", "get_file", "write_file", - "send_email", "normalize_html_json", "process_error", "process_warning", 'calculate_hit'] + "send_email", "normalize_html_json", "process_error", "process_warning", + 'calculate_hit', 'get_ground_hit_dmg_value', 'get_air_hit_dmg_value'] if not sys.version_info >= (3, 7): raise AssertionError('This script requires Python version 3.7 and higher\n' @@ -332,6 +333,10 @@ def normalize_html_json(js: str) -> str: return js +def caught_error(e: Exception): + process_error(str(e), "Unclassified", sys.exc_info(), None, COMMIT_ID, False) + + def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commit_id: str = None, interactive: Optional[bool] = None): """ @@ -351,8 +356,9 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi """ type_, value_, traceback_ = exc_info content = [log_info] - if commit_id: - content += ["Commit id: %s" % commit_id] + if not commit_id: + commit_id = COMMIT_ID + content += ["Commit id: %s" % commit_id] content += [str(value_), str(type_), ''.join(traceback.format_tb(traceback_))] if interactive: