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)
| 2063 | wrapped = dummy_handler |
| 2064 | else: |
| 2065 | def wrapped(self,etype,value,tb,tb_offset=None): |
| 2066 | """wrap CustomTB handler, to protect IPython from user code |
| 2067 | |
| 2068 | This makes it harder (but not impossible) for custom exception |
| 2069 | handlers to crash IPython. |
| 2070 | """ |
| 2071 | try: |
| 2072 | stb = handler(self,etype,value,tb,tb_offset=tb_offset) |
| 2073 | return validate_stb(stb) |
| 2074 | except: |
| 2075 | # clear custom handler immediately |
| 2076 | self.set_custom_exc((), None) |
| 2077 | print("Custom TB Handler failed, unregistering", file=sys.stderr) |
| 2078 | # show the exception in handler first |
| 2079 | stb = self.InteractiveTB.structured_traceback(*sys.exc_info()) |
| 2080 | print(self.InteractiveTB.stb2text(stb)) |
| 2081 | print("The original exception:") |
| 2082 | stb = self.InteractiveTB.structured_traceback( |
| 2083 | etype, value, tb, tb_offset=tb_offset |
| 2084 | ) |
| 2085 | return stb |
| 2086 | |
| 2087 | self.CustomTB = types.MethodType(wrapped,self) |
| 2088 | self.custom_exceptions = exc_tuple |
nothing calls this directly
no test coverage detected