Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move exception_records related methods to errors.py #14084

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions modules/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
exception_records = []


def format_traceback(tb):
return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]


def format_exception(e, tb):
return {"exception": str(e), "traceback": format_traceback(tb)}


def get_exceptions():
try:
return list(reversed(exception_records))
except Exception as e:
return str(e)


def record_exception():
_, e, tb = sys.exc_info()
if e is None:
Expand All @@ -14,8 +29,7 @@ def record_exception():
if exception_records and exception_records[-1] == e:
return

from modules import sysinfo
exception_records.append(sysinfo.format_exception(e, tb))
exception_records.append(format_exception(e, tb))

if len(exception_records) > 5:
exception_records.pop(0)
Expand Down
18 changes: 1 addition & 17 deletions modules/sysinfo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import os
import sys
import traceback

import platform
import hashlib
Expand Down Expand Up @@ -85,7 +84,7 @@ def get_dict():
"Checksum": checksum_token,
"Commandline": sys.argv,
"Torch env info": get_torch_sysinfo(),
"Exceptions": get_exceptions(),
"Exceptions": errors.get_exceptions(),
"CPU": {
"model": platform.processor(),
"count logical": psutil.cpu_count(logical=True),
Expand All @@ -105,21 +104,6 @@ def get_dict():
return res


def format_traceback(tb):
return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]


def format_exception(e, tb):
return {"exception": str(e), "traceback": format_traceback(tb)}


def get_exceptions():
try:
return list(reversed(errors.exception_records))
except Exception as e:
return str(e)


def get_environment():
return {k: os.environ[k] for k in sorted(os.environ) if k in environment_whitelist}

Expand Down