()
| 69 | |
| 70 | @contextlib.contextmanager |
| 71 | def error_handler() -> Generator[None]: |
| 72 | try: |
| 73 | yield |
| 74 | except (Exception, KeyboardInterrupt) as e: |
| 75 | if isinstance(e, FatalError): |
| 76 | msg, ret_code = 'An error has occurred', 1 |
| 77 | elif isinstance(e, KeyboardInterrupt): |
| 78 | msg, ret_code = 'Interrupted (^C)', 130 |
| 79 | else: |
| 80 | msg, ret_code = 'An unexpected error has occurred', 3 |
| 81 | _log_and_exit(msg, ret_code, e, traceback.format_exc()) |