SERVER-31629 Support putting unique codes directly into Status constructors

This commit is contained in:
Mathias Stearn
2017-10-24 13:00:11 -04:00
parent a963b8641c
commit cd26a1d5ee
10 changed files with 33 additions and 22 deletions

View File

@@ -54,17 +54,16 @@ def assignErrorCodes():
def parseSourceFiles( callback ):
"""Walks MongoDB sourcefiles and invokes callback for each AssertLocation found."""
quick = [ "assert" , "Exception"]
quick = ["assert", "Exception", "ErrorCodes::Error"]
patterns = [
re.compile( r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE ) ,
re.compile( r"(?:DB|Assertion)Exception\s*\(\s*(\d+)", re.MULTILINE ),
re.compile( r"(?:DB|Assertion)Exception\s*[({]\s*(\d+)", re.MULTILINE ),
re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)",
re.MULTILINE ),
re.compile( r"ErrorCodes::Error\s*[({]\s*(\d+)", re.MULTILINE )
]
bad = [ re.compile( r"^\s*assert *\(" ) ]
for sourceFile in utils.getAllSourceFiles(prefix='src/mongo/'):
if list_files:
print 'scanning file: ' + sourceFile
@@ -75,13 +74,6 @@ def parseSourceFiles( callback ):
if not any([zz in text for zz in quick]):
continue
# TODO: move check for bad assert type to the linter.
for b in bad:
if b.search(text):
msg = "Bare assert prohibited. Replace with [umwdf]assert"
print( "%s: %s" % (sourceFile, msg) )
raise Exception(msg)
matchiters = [p.finditer(text) for p in patterns]
for matchiter in matchiters:
for match in matchiter: