diff --git a/electrum/base_crash_reporter.py b/electrum/base_crash_reporter.py index 6c10861e5..c443747f8 100644 --- a/electrum/base_crash_reporter.py +++ b/electrum/base_crash_reporter.py @@ -23,15 +23,13 @@ import asyncio import json import locale import traceback -import subprocess import sys -import os from .version import ELECTRUM_VERSION from . import constants from .i18n import _ from .util import make_aiohttp_session -from .logging import describe_os_version, Logger +from .logging import describe_os_version, Logger, get_git_version class BaseCrashReporter(Logger): @@ -95,7 +93,7 @@ class BaseCrashReporter(Logger): def get_additional_info(self): args = { - "app_version": ELECTRUM_VERSION, + "app_version": get_git_version() or ELECTRUM_VERSION, "python_version": sys.version, "os": describe_os_version(), "wallet_type": "unknown", @@ -107,20 +105,8 @@ class BaseCrashReporter(Logger): except: # Maybe the wallet isn't loaded yet pass - try: - args["app_version"] = self.get_git_version() - except: - # This is probably not running from source - pass return args - @staticmethod - def get_git_version(): - dir = os.path.dirname(os.path.realpath(sys.argv[0])) - version = subprocess.check_output( - ['git', 'describe', '--always', '--dirty'], cwd=dir) - return str(version, "utf8").strip() - def _get_traceback_str(self) -> str: return "".join(traceback.format_exception(*self.exc_args)) diff --git a/electrum/logging.py b/electrum/logging.py index 857913425..f3e0a4dd8 100644 --- a/electrum/logging.py +++ b/electrum/logging.py @@ -10,6 +10,7 @@ import os import platform from typing import Optional import copy +import subprocess class LogFormatterForFiles(logging.Formatter): @@ -268,3 +269,14 @@ def describe_os_version() -> str: return "Android {} on {} {} ({})".format(bv.RELEASE, b.BRAND, b.DEVICE, b.DISPLAY) else: return platform.platform() + + +def get_git_version() -> Optional[str]: + dir = os.path.dirname(os.path.realpath(__file__)) + try: + version = subprocess.check_output( + ['git', 'describe', '--always', '--dirty'], cwd=dir) + version = str(version, "utf8").strip() + except Exception: + version = None + return version