##// END OF EJS Templates
revlog: subclass the new `repository.iverifyproblem` Protocol class...
revlog: subclass the new `repository.iverifyproblem` Protocol class This is the same transformation as 3a90a6fd710d did for dirstate, but the CamelCase naming was already cleaned up here. We shouldn't have to explicitly subclass, but I'm doing so to test the interplay of regular attributes and the `attrs` class. Also, PyCharm has a nifty feature that puts a jump point in the gutter to navigate back and forth between the base class and subclasses (and override functions and base class functions) when there's an explicit subclassing. Additionally, PyCharm will immediately flag signature mismatches without a 40m pytype run.

File last commit:

r49730:6000f5b2 default
r53365:4ef6dbc2 default
Show More
logexceptions.py
75 lines | 1.8 KiB | text/x-python | PythonLexer
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191 # logexceptions.py - Write files containing info about Mercurial exceptions
#
Raphaël Gomès
contributor: change mentions of mpm to olivia...
r47575 # Copyright 2017 Olivia Mackall <olivia@selenic.com>
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191 #
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import inspect
import os
import sys
import traceback
import uuid
from mercurial import (
dispatch,
extensions,
)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191 def handleexception(orig, ui):
res = orig(ui)
if not ui.environ.get(b'HGEXCEPTIONSDIR'):
return res
Augie Fackler
formatting: blacken the codebase...
r43346 dest = os.path.join(
ui.environ[b'HGEXCEPTIONSDIR'], str(uuid.uuid4()).encode('ascii')
)
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191
exc_type, exc_value, exc_tb = sys.exc_info()
stack = []
tb = exc_tb
while tb:
stack.append(tb)
tb = tb.tb_next
stack.reverse()
hgframe = 'unknown'
hgline = 'unknown'
# Find the first Mercurial frame in the stack.
for tb in stack:
mod = inspect.getmodule(tb)
if not mod.__name__.startswith(('hg', 'mercurial')):
continue
frame = tb.tb_frame
try:
with open(inspect.getsourcefile(tb), 'r') as fh:
hgline = fh.readlines()[frame.f_lineno - 1].strip()
except (IndexError, OSError):
pass
hgframe = '%s:%d' % (frame.f_code.co_filename, frame.f_lineno)
break
primary = traceback.extract_tb(exc_tb)[-1]
primaryframe = '%s:%d' % (primary.filename, primary.lineno)
with open(dest, 'wb') as fh:
parts = [
str(exc_value),
primaryframe,
hgframe,
hgline,
Gregory Szorc
run-tests: report tests that exception occurred in...
r36054 ui.environ[b'TESTNAME'].decode('utf-8', 'replace'),
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191 ]
fh.write(b'\0'.join(p.encode('utf-8', 'replace') for p in parts))
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
run-tests: mechanism to report exceptions during test execution...
r35191 def extsetup(ui):
Augie Fackler
formatting: blacken the codebase...
r43346 extensions.wrapfunction(dispatch, 'handlecommandexception', handleexception)