# Buggy code
def print_output_event(event, stream, is_terminal):
    if "errorDetail" in event:
        raise StreamOutputError(event["errorDetail"]["message"])

    terminator = ""

    if is_terminal and "stream" not in event:
        # erase current line
        stream.write("%c[2K\r" % 27)
        terminator = "\r"
    elif "progressDetail" in event:
        return

    if "time" in event:
        stream.write("[%s] " % event["time"])

    if "id" in event:
        stream.write("%s: " % event["id"])

    if "from" in event:
        stream.write("(from %s) " % event["from"])

    status = event.get("status", "")

    if "progress" in event:
        stream.write("%s %s%s" % (status, event["progress"], terminator))
    elif "progressDetail" in event:
        detail = event["progressDetail"]
        total = detail.get("total")
        if "current" in detail and total:
            percentage = float(detail["current"]) / float(total) * 100
            stream.write("%s (%.1f%%)%s" % (status, percentage, terminator))
        else:
            stream.write("%s%s" % (status, terminator))
    elif "stream" in event:
        stream.write("%s%s" % (event["stream"], terminator))
    else:
        stream.write("%s%s\n" % (status, terminator))


# Traceback (UnicodeEncodeError)
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 280, in build
File "compose/project.py", line 372, in build
File "compose/service.py", line 1003, in build
File "compose/progress_stream.py", line 23, in stream_output
File "compose/progress_stream.py", line 90, in print_output_event
UnicodeEncodeError: 'ascii' codec can't encode character '\u2013' in position 151: ordinal not in range(128)
[96] Failed to execute script docker-compose
Exited with code 255

# Fixed code
def print_output_event(event, stream, is_terminal):
    if "errorDetail" in event:
        raise StreamOutputError(event["errorDetail"]["message"])

    terminator = ""

    if is_terminal and "stream" not in event:
        # erase current line
        write_to_stream("%c[2K\r" % 27, stream)
        terminator = "\r"
    elif "progressDetail" in event:
        return

    if "time" in event:
        write_to_stream("[%s] " % event["time"], stream)

    if "id" in event:
        write_to_stream("%s: " % event["id"], stream)

    if "from" in event:
        write_to_stream("(from %s) " % event["from"], stream)

    status = event.get("status", "")

    if "progress" in event:
        write_to_stream("%s %s%s" % (status, event["progress"], terminator), stream)
    elif "progressDetail" in event:
        detail = event["progressDetail"]
        total = detail.get("total")
        if "current" in detail and total:
            percentage = float(detail["current"]) / float(total) * 100
            write_to_stream("%s (%.1f%%)%s" % (status, percentage, terminator), stream)
        else:
            write_to_stream("%s%s" % (status, terminator), stream)
    elif "stream" in event:
        write_to_stream("%s%s" % (event["stream"], terminator), stream)
    else:
        write_to_stream("%s%s\n" % (status, terminator), stream)