aboutsummaryrefslogtreecommitdiff
path: root/modules/errors.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2023-05-31 19:16:14 +0300
committerGitHub <noreply@github.com>2023-05-31 19:16:14 +0300
commitd9bd7ada7675d3903181a6a65ba625d82cf88443 (patch)
tree30470f64d84cadc4140023c0bf34c35bb68f79b0 /modules/errors.py
parent78a602ae8c006077ca93913576335a3a33dba7cb (diff)
parent52b8752e6201e24c783f674f8dc0681027e10ea9 (diff)
Merge pull request #10820 from akx/report-error
Add & use modules.errors.print_error
Diffstat (limited to 'modules/errors.py')
-rw-r--r--modules/errors.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/errors.py b/modules/errors.py
index da4694f8..41d8dc93 100644
--- a/modules/errors.py
+++ b/modules/errors.py
@@ -1,7 +1,23 @@
import sys
+import textwrap
import traceback
+def print_error(
+ 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("---")
+
+
def print_error_explanation(message):
lines = message.strip().split("\n")
max_len = max([len(x) for x in lines])