Add & use modules.errors.print_error where currently printing exception info by hand

This commit is contained in:
Aarni Koskela
2023-05-29 08:54:13 +03:00
parent b957dcfece
commit 00dfe27f59
25 changed files with 117 additions and 153 deletions

View File

@@ -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])