Debian Codegraph @

friendly_traceback/debug_helper.py

raw symbols SCIP
1 """Debug helper
2
3 The purpose of this file is to help during development.
4
5 The idea is to silence internal exceptions raised by Friendly
6 itself for most users by redirecting them here, and have them
7 printed only when debugging mode is activated.
8 """
9
10 import inspect
11 import sys
12 from typing import Optional
13
14 from .ft_gettext import current_lang
15
16 _ = current_lang.translate
17
18 # DEBUG is set to True when running with pytest.
19 # It can also be set to True from __main__ or when
20 # using the debug() command in the console.
21
22 DEBUG = False
23 SHOW_DEBUG_HELPER = False
24
25
26 def log_error(exc: Optional[BaseException] = None) -> None:
27 if DEBUG: # pragma: no cover
28 if exc is not None:
29 print(repr(exc))
30 frame = inspect.currentframe().f_back
31 print(f"{frame.f_code.co_filename}, line: {frame.f_lineno}")
32 sys.exit()
33
34
35 def log(*args: str) -> None:
36 if DEBUG:
37 for arg in args:
38 print(arg)
39
40
41 def handle_internal_error(arg: str) -> None:
42 print(_("Fatal error - aborting"), arg)
43 print(_("Please report this issue."))
44 sys.exit()