Skip to content

Add timestamp to unhandled exception output #11

Description

@rocky-d

Enhancement: Timestamp on crash reports

Hi! Looking at the exception handler in main.py:

def handle_exception(exc_type, exc_value, exc_traceback):
    print("Exception type:", exc_type)
    print("Exception value:", exc_value)
    trace_details = traceback.format_exception(exc_type, exc_value, exc_traceback)
    trace_string = "".join(trace_details)
    print("Exception traceback:", trace_string)
    message = f"An error occurred!\n\n{exc_value}\n\n{trace_string}"
    interface.display_error_message(message)
    original_excepthook(exc_type, exc_value, exc_traceback)

sys.excepthook = handle_exception

The handler captures and displays exceptions well, but doesn't include when the crash happened — which is particularly valuable for a data collection tool like DuckTrack where you need to correlate crashes with session events.

Suggestion: dttb is a tiny package that patches sys.excepthook to add timestamps automatically:

import dttb

def my_callback(args: dttb.CallbackArgs) -> None:
    # args.now — datetime of exception
    # args.exc_type, args.exc_value, args.exc_traceback — standard exception info
    trace_string = "".join(traceback.format_exception(args.exc_type, args.exc_value, args.exc_traceback))
    message = f"[{args.now}] An error occurred!\n\n{args.exc_value}\n\n{trace_string}"
    interface.display_error_message(message)

dttb.apply(callback=my_callback)

This integrates cleanly with your existing handler pattern and makes the timestamp available both in the dialog and in any logs.

pip install dttb — https://github.com/rocky-d/dttb

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions