Updated crash_reporter to include crash data

This commit is contained in:
Rhet Turnbull 2022-03-04 20:26:19 -08:00
parent de1900f10a
commit 1227465aa7
2 changed files with 24 additions and 8 deletions

View File

@ -39,7 +39,7 @@ from osxphotos.configoptions import (
ConfigOptionsInvalidError, ConfigOptionsInvalidError,
ConfigOptionsLoadError, ConfigOptionsLoadError,
) )
from osxphotos.crash_reporter import crash_reporter from osxphotos.crash_reporter import crash_reporter, set_crash_data
from osxphotos.datetime_formatter import DateTimeFormatter from osxphotos.datetime_formatter import DateTimeFormatter
from osxphotos.debug import is_debug, set_debug from osxphotos.debug import is_debug, set_debug
from osxphotos.exiftool import get_exiftool_path from osxphotos.exiftool import get_exiftool_path
@ -56,6 +56,7 @@ from osxphotos.phototemplate import PhotoTemplate, RenderOptions
from osxphotos.queryoptions import QueryOptions from osxphotos.queryoptions import QueryOptions
from osxphotos.uti import get_preferred_uti_extension from osxphotos.uti import get_preferred_uti_extension
from osxphotos.utils import format_sec_to_hhmmss, normalize_fs_path from osxphotos.utils import format_sec_to_hhmmss, normalize_fs_path
from .common import ( from .common import (
CLI_COLOR_ERROR, CLI_COLOR_ERROR,
CLI_COLOR_WARNING, CLI_COLOR_WARNING,
@ -63,13 +64,13 @@ from .common import (
DB_OPTION, DB_OPTION,
DEBUG_OPTIONS, DEBUG_OPTIONS,
DELETED_OPTIONS, DELETED_OPTIONS,
get_photos_db,
JSON_OPTION, JSON_OPTION,
load_uuid_from_file,
noop,
OSXPHOTOS_CRASH_LOG, OSXPHOTOS_CRASH_LOG,
OSXPHOTOS_HIDDEN, OSXPHOTOS_HIDDEN,
QUERY_OPTIONS, QUERY_OPTIONS,
get_photos_db,
load_uuid_from_file,
noop,
verbose_print, verbose_print,
) )
from .help import ExportCommand, get_help_msg from .help import ExportCommand, get_help_msg
@ -781,7 +782,7 @@ def export(
preview_if_missing, preview_if_missing,
profile, profile,
profile_sort, profile_sort,
debug, debug, # debug, watch, breakpoint handled in cli/__init__.py
watch, watch,
breakpoint, breakpoint,
): ):
@ -800,8 +801,7 @@ def export(
# capture locals for use with ConfigOptions before changing any of them # capture locals for use with ConfigOptions before changing any of them
locals_ = locals() locals_ = locals()
if debug: set_crash_data("locals", locals_)
set_debug(True)
if profile: if profile:
click.echo("Profiling...") click.echo("Profiling...")
@ -983,6 +983,8 @@ def export(
verbose_ = verbose_print(verbose, timestamp, rich=True, highlight=False) verbose_ = verbose_print(verbose, timestamp, rich=True, highlight=False)
verbose_(f"Loaded options from file {load_config}") verbose_(f"Loaded options from file {load_config}")
set_crash_data("cfg", cfg.asdict())
verbose_(f"osxphotos version {__version__}") verbose_(f"osxphotos version {__version__}")
# validate options # validate options

View File

@ -8,6 +8,16 @@ import traceback
from rich import print from rich import print
from ._version import __version__
# store data to print out in crash log, set by set_crash_data
CRASH_DATA = {}
def set_crash_data(key_, data):
"""Set data to be printed in crash log"""
CRASH_DATA[key_] = data
def crash_reporter(filename, message, title, postamble, *extra_args): def crash_reporter(filename, message, title, postamble, *extra_args):
"""Create a crash dump file on error named filename """Create a crash dump file on error named filename
@ -30,9 +40,13 @@ def crash_reporter(filename, message, title, postamble, *extra_args):
with open(filename, "w") as f: with open(filename, "w") as f:
f.write(f"{title}\n") f.write(f"{title}\n")
f.write(f"Created: {datetime.datetime.now()}\n") f.write(f"Created: {datetime.datetime.now()}\n")
f.write(f"Python version: {sys.version}\n") f.write(f"osxphotos version: {__version__}\n")
f.write(f"Platform: {platform.platform()}\n") f.write(f"Platform: {platform.platform()}\n")
f.write(f"Python version: {sys.version}\n")
f.write(f"sys.argv: {sys.argv}\n") f.write(f"sys.argv: {sys.argv}\n")
f.write("CRASH_DATA: \\n")
for k, v in CRASH_DATA.items():
f.write(f"{k}: {v}\n")
for arg in extra_args: for arg in extra_args:
f.write(f"{arg}\n") f.write(f"{arg}\n")
f.write(f"Error: {e}\n") f.write(f"Error: {e}\n")