# Buggy code
def write(cls, error_type, rp, exc):
    """Add line to log file indicating error exc with file rp"""
    if not Globals.isbackup_writer:
        return Globals.backup_writer.log.ErrorLog.write(error_type, rp, exc)
    logstr = cls.get_log_string(error_type, rp, exc)
    Log(logstr, 2)
    if isinstance(logstr, bytes):
        logstr = logstr.decode("utf-8")
    if Globals.null_separator:
        logstr += "\0"
    else:
        logstr = re.sub("\n", " ", logstr)
        logstr += "\n"
    cls._log_fileobj.write(logstr)


# Traceback (TypeError)
UpdateError: 'data/some/sub/dir/changed-file/rdiff-backup.tmp.266' does not match source
Exception 'a bytes-like object is required, not 'str'' raised of class '<class 'TypeError'>':
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 348, in take_action
Backup(rps[0], rps[1])
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 434, in Backup
backup.Mirror_and_increment(rpin, rpout, incdir)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 55, in Mirror_and_increment
DestS.patch_and_increment(dest_rpath, source_diffiter, inc_rpath)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 281, in patch_and_increment
ITR(diff.index, diff)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/rorpiter.py", line 313, in __call__
last_branch.fast_process(*args)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 781, in fast_process
if self.patch_to_temp(mirror_rp, diff_rorp, tf):
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 637, in patch_to_temp
return self.matches_cached_rorp(diff_rorp, new)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 691, in matches_cached_rorp
"temp file '%s' does not match source" % new_rp.get_safepath())
File "/usr/lib64/python3.6/site-packages/rdiff_backup/log.py", line 313, in write_if_open
cls.write(error_type, rp, exc)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/log.py", line 293, in write
cls._log_fileobj.write(logstr)

Traceback (most recent call last):
File "/usr/bin/rdiff-backup", line 32, in <module>
rdiff_backup.Main.error_check_Main(sys.argv[1:])
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 348, in take_action
Backup(rps[0], rps[1])
File "/usr/lib64/python3.6/site-packages/rdiff_backup/Main.py", line 434, in Backup
backup.Mirror_and_increment(rpin, rpout, incdir)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 55, in Mirror_and_increment
DestS.patch_and_increment(dest_rpath, source_diffiter, inc_rpath)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 281, in patch_and_increment
ITR(diff.index, diff)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/rorpiter.py", line 313, in __call__
last_branch.fast_process(*args)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 781, in fast_process
if self.patch_to_temp(mirror_rp, diff_rorp, tf):
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 637, in patch_to_temp
return self.matches_cached_rorp(diff_rorp, new)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/backup.py", line 691, in matches_cached_rorp
"temp file '%s' does not match source" % new_rp.get_safepath())
File "/usr/lib64/python3.6/site-packages/rdiff_backup/log.py", line 313, in write_if_open
cls.write(error_type, rp, exc)
File "/usr/lib64/python3.6/site-packages/rdiff_backup/log.py", line 293, in write
cls._log_fileobj.write(logstr)
TypeError: a bytes-like object is required, not 'str'

# Fixed code
def write(cls, error_type, rp, exc):
    """Add line to log file indicating error exc with file rp"""
    if not Globals.isbackup_writer:
        return Globals.backup_writer.log.ErrorLog.write(error_type, rp, exc)
    logstr = cls.get_log_string(error_type, rp, exc)
    Log(logstr, 2)
    if Globals.null_separator:
        logstr += "\0"
    else:
        logstr = re.sub("\n", " ", logstr)
        logstr += "\n"
    cls._log_fileobj.write(_to_bytes(logstr))