wrap CustomTB handler, to protect IPython from user code This makes it harder (but not impossible) for custom exception handlers to crash IPython.
(self,etype,value,tb,tb_offset=None)
| 1908 | wrapped = dummy_handler |
| 1909 | else: |
| 1910 | def wrapped(self,etype,value,tb,tb_offset=None): |
| 1911 | """wrap CustomTB handler, to protect IPython from user code |
| 1912 | |
| 1913 | This makes it harder (but not impossible) for custom exception |
| 1914 | handlers to crash IPython. |
| 1915 | """ |
| 1916 | try: |
| 1917 | stb = handler(self,etype,value,tb,tb_offset=tb_offset) |
| 1918 | return validate_stb(stb) |
| 1919 | except: |
| 1920 | # clear custom handler immediately |
| 1921 | self.set_custom_exc((), None) |
| 1922 | print("Custom TB Handler failed, unregistering", file=sys.stderr) |
| 1923 | # show the exception in handler first |
| 1924 | stb = self.InteractiveTB.structured_traceback(*sys.exc_info()) |
| 1925 | print(self.InteractiveTB.stb2text(stb)) |
| 1926 | print("The original exception:") |
| 1927 | stb = self.InteractiveTB.structured_traceback( |
| 1928 | (etype,value,tb), tb_offset=tb_offset |
| 1929 | ) |
| 1930 | return stb |
| 1931 | |
| 1932 | self.CustomTB = types.MethodType(wrapped,self) |
| 1933 | self.custom_exceptions = exc_tuple |
nothing calls this directly
no test coverage detected