PeterJCLaw / srcomp-cli

Command line tools for interacting with the state of the Student Robotics Competition
https://github.com/PeterJCLaw/srcomp/wiki
0 stars 2 forks source link

Emojis in commit message can lead to a UnicodeDecodeError on deploy #9

Closed sedders123 closed 1 year ago

sedders123 commented 3 years ago

When deploying https://github.com/srobo/sr2020-comp/commit/abfbf368e64fc33f76fc76a9798a9479713ff357 (message 🏆 Add awards.yml! 🎉🥳🙌) using srcomp deploy. I got the following stack trace

Traceback (most recent call last):
  File "/mnt/c/Users/james/Projects/sr/srcomp-venv-wsl/bin/srcomp", line 33, in <module>
    sys.exit(load_entry_point('sr.comp.cli', 'console_scripts', 'srcomp')())
  File "/mnt/c/Users/james/Projects/sr/srcomp-cli/sr/comp/cli/command_line.py", line 79, in main
    settings.func(settings)
  File "/mnt/c/Users/james/Projects/sr/srcomp-cli/sr/comp/cli/deploy.py", line 265, in command
    run_deployments(args, compstate, hosts)
  File "/mnt/c/Users/james/Projects/sr/srcomp-cli/sr/comp/cli/deploy.py", line 244, in run_deployments
    retcode = deploy_to(compstate, host, revision, args.verbose)
  File "/mnt/c/Users/james/Projects/sr/srcomp-cli/sr/comp/cli/deploy.py", line 123, in deploy_to
    print_buffer(stderr)
  File "/mnt/c/Users/james/Projects/sr/srcomp-cli/sr/comp/cli/deploy.py", line 42, in print_buffer
    print(prefix + prefix.join(buf.readlines()).strip())
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f3c6' in position 271: ordinal not in range(256)

Notably I didn't get this error when deploying https://github.com/srobo/sr2020-comp/commit/07cb8b744fb2125328a417516113af86f93a8cc9 (message 🔮 Add tiebreaker to schedule) which also contained an emoji.

Python Version: 3.7.3 OS: Windows 10.0.18363 Build 18363 Run under Windows Subsystem for Linux v1

PeterJCLaw commented 3 years ago

When you deployed https://github.com/srobo/sr2020-comp/commit/07cb8b744fb2125328a417516113af86f93a8cc9, was that HEAD at the time? srcomp-cli shows the message of HEAD at the point of deploy (rather than the whole history), so that could explain that part.

sedders123 commented 3 years ago

https://github.com/srobo/sr2020-comp/commit/c361451850f603b8a9e96ac5ea6e3725483be1d7 would have been at HEAD when https://github.com/srobo/sr2020-comp/commit/07cb8b744fb2125328a417516113af86f93a8cc9 was deployed, so it does sound like the displaying of the HEAD message could be at fault.

PeterJCLaw commented 3 years ago

It looks like this is a result of sys.stdout.encoding being iso-8859-1 under some WSL operating systems (notably Penguin). Setting the locale there does solve this. However as deploy is a fairly critical command and doesn't have any way to roll back a partially applied deploy I'm going to see if I can put a fix in for this.

In [1]: import sys
   ...: orig_write = sys.__stdout__.write
   ...: def write(text, *a, **k):
   ...:     encoding = sys.stdout.encoding
   ...:     text = text.encode(encoding, errors='replace').decode(encoding)
   ...:     # text = ''.join(reversed(text))
   ...:     orig_write(text, *a, **k)
   ...: sys.stdout.write = write

Seems like a useful starting point for solving this.