23andMe / Yamale

A schema and validator for YAML.
MIT License
679 stars 88 forks source link

Check for UnicodeEncodeError when printing the success message #191

Closed sirykd closed 2 years ago

sirykd commented 2 years ago

Hi,

Thanks for your great work!

There exists an issue I've encountered in several environments with printing "👍". The problem is that we get "Validation failed!" trying to print "Validation success! 👍" which is both funny and incorrect.

The issue can be reproduced in ubuntu docker, but it is not limited to docker in my experience.

I prefer to keep the original message when possible, which dictates the try ... except approach in the PR.

mildebrandt commented 2 years ago

Hi, thanks for your interest in Yamale!

Can you provide some recreation steps? I ran Yamale within an Ubuntu docker container and the "Validation success! 👍" message prints without error.

sirykd commented 2 years ago

Can you provide some recreation steps? I ran Yamale within an Ubuntu docker container and the "Validation success! 👍" message prints without error.

To clarify, the issue is image-dependent if we talk about Docker (e.g. generating locale can be a hot-fix).

Please check the following Dockerfile to reproduce it:

FROM ubuntu:18.04

RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install -y python3-pip
RUN pip3 install yamale

Build an image and run yamale:

docker build -t unicode-fail-image .
docker run unicode-fail-image yamale

Expected result:

...
Validation failed!
'ascii' codec can't encode character '\U0001f44d' in position 20: ordinal not in range(128)
mildebrandt commented 2 years ago

Well that's unfortunate, I'm surprised it took 5 years for someone to have an issue with that. Thanks for the recreation steps.

mildebrandt commented 2 years ago

Your fix is in release 4.0.3, thanks for the contribution!

sirykd commented 2 years ago

Your fix is in release 4.0.3, thanks for the contribution!

Thanks!