|
8 | 8 | import inspect |
9 | 9 | import json |
10 | 10 | import os |
11 | | -import pdb |
12 | 11 | import re |
13 | 12 | import sys |
14 | 13 | import time |
|
54 | 53 | md_printer, |
55 | 54 | set_help_md_as_docstring, |
56 | 55 | set_parse_doc_help_md_as_docstring, |
| 56 | + debug_exceptions, |
57 | 57 | ) |
58 | 58 | from wdoc.utils.misc import ( # debug_chain, |
59 | 59 | cache_dir, |
@@ -1857,46 +1857,3 @@ def parse_doc( |
1857 | 1857 | f.write(file_content) |
1858 | 1858 |
|
1859 | 1859 | return result |
1860 | | - |
1861 | | - |
1862 | | -def debug_exceptions(instance: Optional[wdoc] = None) -> None: |
1863 | | - "open a debugger if --debug is set" |
1864 | | - |
1865 | | - def handle_exception(exc_type, exc_value, exc_traceback): |
1866 | | - if not issubclass(exc_type, KeyboardInterrupt): |
1867 | | - |
1868 | | - def p(message: str) -> None: |
1869 | | - "print error, in red if possible" |
1870 | | - if instance: |
1871 | | - logger.exception(instance.ntfy(message)) |
1872 | | - else: |
1873 | | - try: |
1874 | | - logger.warning(message) |
1875 | | - except Exception: |
1876 | | - print(message) |
1877 | | - |
1878 | | - p( |
1879 | | - "\n--verbose was used so opening debug console at the " |
1880 | | - "appropriate frame. Press 'c' to continue to the frame " |
1881 | | - "of this print." |
1882 | | - ) |
1883 | | - p( |
1884 | | - "Please open an issue on github and include the trace. It's " |
1885 | | - "tremendously useful for me as there are many small bugs that " |
1886 | | - "can be quickly squashed if users just told me about it :)" |
1887 | | - ) |
1888 | | - [p(line) for line in traceback.format_tb(exc_traceback)] |
1889 | | - p(str(exc_type) + " : " + str(exc_value)) |
1890 | | - if hasattr(exc_value, "__cause__") and hasattr( |
1891 | | - exc_value.__cause__, "__traceback__" |
1892 | | - ): |
1893 | | - p("Detected a cause to the exception, opening the cause first") |
1894 | | - pdb.post_mortem(exc_value.__cause__.__traceback__) |
1895 | | - p("Out of the __cause__, now debugging the higher traceback:") |
1896 | | - pdb.post_mortem(exc_traceback) |
1897 | | - p("You are now in the exception handling frame.") |
1898 | | - breakpoint() |
1899 | | - sys.exit(1) |
1900 | | - |
1901 | | - sys.excepthook = handle_exception |
1902 | | - faulthandler.enable() |
0 commit comments