Skip to content

Commit

Permalink
Bug 1288202 - Ignore malformed PERFHERDER_DATA lines (#1714)
Browse files Browse the repository at this point in the history
Sometimes a non-valid PERFHERDER string can be found in a log because
of debugging code or other reasons. There's no reason to not parse the rest
of the log for a job if we find one of them.
  • Loading branch information
wlach committed Jul 21, 2016
1 parent 47b14a0 commit 0656dfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/log_parser/test_performance_parser.py
@@ -0,0 +1,12 @@
from treeherder.log_parser.parsers import PerformanceParser


def test_performance_log_parsing_malformed_perfherder_data():
"""
If we have one malformed perfherder data line, we should just ignore
it and still be able to parse the next one
"""
parser = PerformanceParser()
parser.parse_line("PERFHERDER_DATA: {oh noes i am not valid json}", 1)
parser.parse_line("PERFHERDER_DATA: {}", 2)
assert parser.get_artifact() == [{}]
12 changes: 9 additions & 3 deletions treeherder/log_parser/parsers.py
@@ -1,11 +1,14 @@
import datetime
import json
import logging
import re

from django.conf import settings

from treeherder.etl.buildbot import RESULT_DICT

logger = logging.getLogger(__name__)


class ParserBase(object):
"""
Expand Down Expand Up @@ -452,9 +455,12 @@ def __init__(self):
def parse_line(self, line, lineno):
match = self.RE_PERFORMANCE.match(line)
if match:
# this will throw an exception if the json parsing breaks, but
# that's the behaviour we want
self.artifact.append(json.loads(match.group(1)))
try:
dict = json.loads(match.group(1))
self.artifact.append(dict)
except ValueError:
logger.warning("Unable to parse Perfherder data from line: %s",
line)
# don't mark as complete, in case there are multiple performance
# artifacts
# self.complete = True

0 comments on commit 0656dfa

Please sign in to comment.