# Buggy code
def PrintLine(self):
    """ "Return a string with combined values from the lexer."""
    year = getattr(self.attributes, "iyear", None)
    month = getattr(self.attributes, "imonth", None)
    day = getattr(self.attributes, "iday", None)

    if None in [year, month, day]:
        date_string = "[DATE NOT SET]"
    else:
        try:
            year = int(year, 10)
            month = int(month, 10)
            day = int(day, 10)

            date_string = "{0:04d}-{1:02d}-{2:02d}".format(year, month, day)
        except ValueError:
            date_string = "[DATE INVALID]"

    time_string = getattr(self.attributes, "time", "[TIME NOT SET]")
    hostname_string = getattr(self.attributes, "hostname", "HOSTNAME NOT SET")
    reporter_string = getattr(self.attributes, "reporter", "[REPORTER NOT SET]")
    body_string = getattr(self.attributes, "body", "[BODY NOT SET]")

    # TODO: this is a work in progress. The reason for the try-catch is that
    # the text parser is handed a non-text file and must deal with converting
    # arbitrary binary data.
    try:
        line = "{0:s} {1:s} [{2:s}] {3:s} => {4:s}".format(
            date_string, time_string, hostname_string, reporter_string, body_string
        )
    except UnicodeError:
        line = "Unable to print line - due to encoding error."

    return line


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/engine/worker.py", line 169, in _ParseFileEntryWithParser
parser_object.UpdateChainAndParse(self._parser_mediator)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/interface.py", line 72, in UpdateChainAndParse
self.Parse(parser_mediator, **kwargs)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/interface.py", line 256, in Parse
self.ParseFileObject(parser_mediator, file_object, **kwargs)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/text_parser.py", line 160, in ParseFileObject
_ = self.NextToken()
File "/usr/lib/python2.7/dist-packages/plaso/lib/lexer.py", line 191, in NextToken
return Lexer.NextToken(self)
File "/usr/lib/python2.7/dist-packages/plaso/lib/lexer.py", line 99, in NextToken
possible_next_state = callback(string=m.group(0), match=m)
File "/usr/lib/python2.7/dist-packages/plaso/parsers/text_parser.py", line 119, in ParseIncomplete
self.attributes['body'] += match.group(0)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

# Fixed code
def PrintLine(self):
    """ "Return a string with combined values from the lexer."""
    year = getattr(self.attributes, "iyear", None)
    month = getattr(self.attributes, "imonth", None)
    day = getattr(self.attributes, "iday", None)

    if None in [year, month, day]:
        date_string = "[DATE NOT SET]"
    else:
        try:
            year = int(year, 10)
            month = int(month, 10)
            day = int(day, 10)

            date_string = "{0:04d}-{1:02d}-{2:02d}".format(year, month, day)
        except ValueError:
            date_string = "[DATE INVALID]"

    time_string = getattr(self.attributes, "time", "[TIME NOT SET]")
    hostname_string = getattr(self.attributes, "hostname", "HOSTNAME NOT SET")
    reporter_string = getattr(self.attributes, "reporter", "[REPORTER NOT SET]")
    body_string = getattr(self.attributes, "body", "[BODY NOT SET]")

    # TODO: this is a work in progress. The reason for the try-catch is that
    # the text parser is handed a non-text file and must deal with converting
    # arbitrary binary data.
    try:
        line = "{0:s} {1:s} [{2:s}] {3:s} => {4:s}".format(
            date_string, time_string, hostname_string, reporter_string, body_string
        )
    except UnicodeError:
        line = "Unable to print line - due to encoding error."

    return line