fix(bin/linja): catch exception when parsing FlycheckItem

fix #452
This commit is contained in:
Soonho Kong 2015-03-25 13:53:53 -04:00
parent 4c434f4c02
commit d39478a028

View file

@ -132,11 +132,12 @@ class FlycheckItem:
def loc(self): def loc(self):
return (self.filename, self.ty, self.lineno, self.colno) return (self.filename, self.ty, self.lineno, self.colno)
@classmethod @classmethod
def fromString(cls, text): def fromString(cls, target, text):
# Filter out empty lines # Filter out empty lines
lines = [line for line in text.splitlines() if len(line) > 0] lines = [line for line in text.splitlines() if len(line) > 0]
# Throw the first and last lines (header/footer) # Throw the first and last lines (header/footer)
lines = lines[1:-1] lines = lines[1:-1]
try:
firstLine = lines[0] firstLine = lines[0]
items = [item.strip() for item in firstLine.split(":")] items = [item.strip() for item in firstLine.split(":")]
filename = items[0] filename = items[0]
@ -146,6 +147,8 @@ class FlycheckItem:
msg = ":".join(items[4:]) + "\n" + "\n".join(lines[1:]) msg = ":".join(items[4:]) + "\n" + "\n".join(lines[1:])
msg = msg.strip() msg = msg.strip()
return cls(filename, lineno, colno, ty, msg) return cls(filename, lineno, colno, ty, msg)
except:
return cls(target, 1, 0, "error", " ".join(lines))
@python_2_unicode_compatible @python_2_unicode_compatible
class FlycheckItemList: class FlycheckItemList:
@ -178,7 +181,7 @@ class FlycheckItemList:
self.items = newItems self.items = newItems
@classmethod @classmethod
def fromString(cls, text): def fromString(cls, target, text):
items = [] items = []
tmpBuffer = "" tmpBuffer = ""
ignore = True ignore = True
@ -190,7 +193,7 @@ class FlycheckItemList:
ignore = False ignore = False
elif line.startswith(g_flycheck_footer): elif line.startswith(g_flycheck_footer):
tmpBuffer = tmpBuffer + line + "\n" tmpBuffer = tmpBuffer + line + "\n"
items.append(FlycheckItem.fromString(tmpBuffer.strip())) items.append(FlycheckItem.fromString(target, tmpBuffer.strip()))
tmpBuffer = "" tmpBuffer = ""
ignore = True ignore = True
elif not ignore: elif not ignore:
@ -481,7 +484,7 @@ def process_lean_output(target, out, args, using_hlean):
print(out) print(out)
return return
# Parse, filter, and remove extra items # Parse, filter, and remove extra items
flycheckItemList = FlycheckItemList.fromString(out) flycheckItemList = FlycheckItemList.fromString(target, out)
flycheckItemList.filter(lambda item: item.filename == target) flycheckItemList.filter(lambda item: item.filename == target)
flycheckItemList.removeExtraItemsStartswith("failed to add declaration") flycheckItemList.removeExtraItemsStartswith("failed to add declaration")
# Only keep n items in the list. # Only keep n items in the list.