diff --git a/src/python/pants/bin/pants_loader.py b/src/python/pants/bin/pants_loader.py index d9f6c704ae2..cc1586de9c4 100644 --- a/src/python/pants/bin/pants_loader.py +++ b/src/python/pants/bin/pants_loader.py @@ -9,6 +9,7 @@ import os import warnings from builtins import object +from textwrap import dedent class PantsLoader(object): @@ -37,14 +38,18 @@ def ensure_locale(cls): # libraries called by Pants may fail with more obscure errors. encoding = locale.getpreferredencoding() if encoding.lower() != 'utf-8' and os.environ.get(cls.ENCODING_IGNORE_ENV_VAR, None) is None: - raise cls.InvalidLocaleError( - 'System preferred encoding is `{}`, but `UTF-8` is required.\n' - 'Check and set the LC_* and LANG environment settings. Example:\n' - ' LC_ALL=en_US.UTF-8\n' - ' LANG=en_US.UTF-8\n' - 'To bypass this error, please file an issue and then set:\n' - ' {}=1'.format(encoding, cls.ENCODING_IGNORE_ENV_VAR) - ) + raise cls.InvalidLocaleError(dedent("""\ + Your system's preferred encoding is `{}`, but Pants requires `UTF-8`. + Specifically, Python's `locale.getpreferredencoding()` must resolve to `UTF-8`. + + Fix it by setting the LC_* and LANG environment settings. Example: + LC_ALL=en_US.UTF-8 + LANG=en_US.UTF-8 + Or, bypass it by setting the below environment variable. + {}=1 + Note: we cannot guarantee consistent behavior with this bypass enabled. + """.format(encoding, cls.ENCODING_IGNORE_ENV_VAR) + )) @staticmethod def determine_entrypoint(env_var, default): diff --git a/tests/python/pants_test/bin/test_loader_integration.py b/tests/python/pants_test/bin/test_loader_integration.py index 03445043aa2..96e10807947 100644 --- a/tests/python/pants_test/bin/test_loader_integration.py +++ b/tests/python/pants_test/bin/test_loader_integration.py @@ -13,7 +13,7 @@ def test_invalid_locale(self): bypass_env = PantsLoader.ENCODING_IGNORE_ENV_VAR pants_run = self.run_pants(command=['help'], extra_env={'LC_ALL': 'iNvALiD-lOcALe'}) self.assert_failure(pants_run) - self.assertIn('System preferred encoding is', pants_run.stderr_data) + self.assertIn('Pants requires', pants_run.stderr_data) self.assertIn(bypass_env, pants_run.stderr_data) pants_run = self.run_pants(command=['help'], extra_env={'LC_ALL': 'iNvALiD-lOcALe',