diff options
author | AUTOMATIC <16777216c@gmail.com> | 2023-06-01 05:42:50 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2023-06-01 05:42:50 +0000 |
commit | b3390a984081950c626070889580e01727689921 (patch) | |
tree | f1fb3352f91d70034d54a99c220f1ca594d8b3dc /modules/errors.py | |
parent | 0cc05fc492a9360d3b2f1b3f64c7d74f9041f74e (diff) | |
parent | 36888092afa82ee248bc947229f813b453629317 (diff) | |
download | stable-diffusion-webui-gfx803-b3390a984081950c626070889580e01727689921.tar.gz stable-diffusion-webui-gfx803-b3390a984081950c626070889580e01727689921.tar.bz2 stable-diffusion-webui-gfx803-b3390a984081950c626070889580e01727689921.zip |
Merge branch 'dev' into startup-profile
Diffstat (limited to 'modules/errors.py')
-rw-r--r-- | modules/errors.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/modules/errors.py b/modules/errors.py index f6b80dbb..e408f500 100644 --- a/modules/errors.py +++ b/modules/errors.py @@ -1,7 +1,19 @@ import sys
+import textwrap
import traceback
+def report(message: str, *, exc_info: bool = False) -> None:
+ """
+ Print an error message to stderr, with optional traceback.
+ """
+ for line in message.splitlines():
+ print("***", line, file=sys.stderr)
+ if exc_info:
+ print(textwrap.indent(traceback.format_exc(), " "), file=sys.stderr)
+ print("---", file=sys.stderr)
+
+
def print_error_explanation(message):
lines = message.strip().split("\n")
max_len = max([len(x) for x in lines])
@@ -12,9 +24,13 @@ def print_error_explanation(message): print('=' * max_len, file=sys.stderr)
-def display(e: Exception, task):
+def display(e: Exception, task, *, full_traceback=False):
print(f"{task or 'error'}: {type(e).__name__}", file=sys.stderr)
- print(traceback.format_exc(), file=sys.stderr)
+ te = traceback.TracebackException.from_exception(e)
+ if full_traceback:
+ # include frames leading up to the try-catch block
+ te.stack = traceback.StackSummary(traceback.extract_stack()[:-2] + te.stack)
+ print(*te.format(), sep="", file=sys.stderr)
message = str(e)
if "copying a param with shape torch.Size([640, 1024]) from checkpoint, the shape in current model is torch.Size([640, 768])" in message:
|