# Buggy code
def ustring(self, indent, color, msg, prefix="", suffix="", endc=None):
    if endc is None:
        endc = self.ENDC

    indent *= " "
    fmt = "{0}{1}{2}{3}{4}{5}"

    try:
        return fmt.format(indent, color, prefix, msg, endc, suffix)
    except UnicodeDecodeError:
        return fmt.format(
            indent, color, prefix, salt.utils.stringutils.to_unicode(msg), endc, suffix
        )


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/usr/local/bin/salt", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/root/salt/scripts/salt", line 10, in <module>
salt_main()
File "/root/salt/salt/scripts.py", line 480, in salt_main
client.run()
File "/root/salt/salt/cli/salt.py", line 195, in run
self._output_ret(ret_, out, retcode=retcode)
File "/root/salt/salt/cli/salt.py", line 374, in _output_ret
_retcode=retcode)
File "/root/salt/salt/output/__init__.py", line 94, in display_output
display_data = try_printout(data, out, opts, **kwargs)
File "/root/salt/salt/output/__init__.py", line 41, in try_printout
printout = get_printout(out, opts)(data, **kwargs)
File "/root/salt/salt/output/highstate.py", line 146, in output
for host, hostdata in six.iteritems(data)
File "/root/salt/salt/output/highstate.py", line 225, in _format_host
schanged, ctext = _format_changes(ret['changes'], orchestration)
File "/root/salt/salt/output/highstate.py", line 516, in _format_changes
ctext = _nested_changes(changes)
File "/root/salt/salt/output/highstate.py", line 489, in _nested_changes
nested_indent=14)
File "/root/salt/salt/output/__init__.py", line 203, in out_format
return try_printout(data, out, opts, **kwargs)
File "/root/salt/salt/output/__init__.py", line 41, in try_printout
printout = get_printout(out, opts)(data, **kwargs)
File "/root/salt/salt/output/nested.py", line 186, in output
return '\n'.join(nest.display(ret, base_indent, '', []))
File "/root/salt/salt/output/nested.py", line 173, in display
self.display(val, indent + 4, '', out)
File "/root/salt/salt/output/nested.py", line 173, in display
self.display(val, indent + 4, '', out)
File "/root/salt/salt/output/nested.py", line 173, in display
self.display(val, indent + 4, '', out)
File "/root/salt/salt/output/nested.py", line 87, in display
ret = salt.utils.stringutils.to_unicode(ret)
File "/root/salt/salt/utils/stringutils.py", line 110, in to_unicode
return s.decode('utf-8', errors)
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-14: invalid continuation byte

# Fixed code
def ustring(self, indent, color, msg, prefix="", suffix="", endc=None):
    if endc is None:
        endc = self.ENDC

    indent *= " "
    fmt = "{0}{1}{2}{3}{4}{5}"

    try:
        return fmt.format(indent, color, prefix, msg, endc, suffix)
    except UnicodeDecodeError:
        try:
            return fmt.format(
                indent,
                color,
                prefix,
                salt.utils.stringutils.to_unicode(msg),
                endc,
                suffix,
            )
        except UnicodeDecodeError:
            # msg contains binary data that can't be decoded
            return str(fmt).format(  # future lint: disable=blacklisted-function
                indent, color, prefix, msg, endc, suffix
            )