Handle an exception, call for compatible with sys.excepthook
(
self,
etype: type[BaseException],
evalue: BaseException,
etb: types.TracebackType,
)
| 146 | crash_report_fname = self.crash_report_fname) |
| 147 | |
| 148 | def __call__( |
| 149 | self, |
| 150 | etype: type[BaseException], |
| 151 | evalue: BaseException, |
| 152 | etb: types.TracebackType, |
| 153 | ) -> None: |
| 154 | """Handle an exception, call for compatible with sys.excepthook""" |
| 155 | |
| 156 | # do not allow the crash handler to be called twice without reinstalling it |
| 157 | # this prevents unlikely errors in the crash handling from entering an |
| 158 | # infinite loop. |
| 159 | sys.excepthook = sys.__excepthook__ |
| 160 | |
| 161 | |
| 162 | # Use this ONLY for developer debugging (keep commented out for release) |
| 163 | ipython_dir = getattr(self.app, "ipython_dir", None) |
| 164 | if ipython_dir is not None: |
| 165 | assert isinstance(ipython_dir, str) |
| 166 | rptdir = Path(ipython_dir) |
| 167 | else: |
| 168 | rptdir = Path.cwd() |
| 169 | if not rptdir.is_dir(): |
| 170 | rptdir = Path.cwd() |
| 171 | report_name = rptdir / self.crash_report_fname |
| 172 | # write the report filename into the instance dict so it can get |
| 173 | # properly expanded out in the user message template |
| 174 | self.crash_report_fname = str(report_name) |
| 175 | self.info["crash_report_fname"] = str(report_name) |
| 176 | TBhandler = ultratb.VerboseTB( |
| 177 | theme_name="nocolor", |
| 178 | long_header=True, |
| 179 | call_pdb=self.call_pdb, |
| 180 | ) |
| 181 | if self.call_pdb: |
| 182 | TBhandler(etype,evalue,etb) |
| 183 | return |
| 184 | else: |
| 185 | traceback = TBhandler.text(etype,evalue,etb,context=31) |
| 186 | |
| 187 | # print traceback to screen |
| 188 | if self.show_crash_traceback: |
| 189 | print(traceback, file=sys.stderr) |
| 190 | |
| 191 | # and generate a complete report on disk |
| 192 | try: |
| 193 | report = open(report_name, "w", encoding="utf-8") |
| 194 | except: |
| 195 | print('Could not create crash report on disk.', file=sys.stderr) |
| 196 | return |
| 197 | |
| 198 | with report: |
| 199 | # Inform user on stderr of what happened |
| 200 | print('\n'+'*'*70+'\n', file=sys.stderr) |
| 201 | print(self.message_template.format(**self.info), file=sys.stderr) |
| 202 | |
| 203 | # Construct report on disk |
| 204 | report.write(self.make_report(str(traceback))) |
| 205 |
nothing calls this directly
no test coverage detected