From ec9453d3562b269d5245efd4c02c2c38a21d68f8 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 15 Nov 2016 09:27:57 -0800 Subject: [PATCH] [python] do not crash when reporting invalid locales Summary: When `LC_CTYPE` has an invalid value, `locale.getdefaultlocale()` raises `ValueError` and infer crashes, which is embarrassing. Catch these errors and report appropriately. fixes #483 Reviewed By: akotulski Differential Revision: D4182880 fbshipit-source-id: 31edcf7 --- infer/lib/python/infer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/infer/lib/python/infer.py b/infer/lib/python/infer.py index 506c91b52..54d63377f 100755 --- a/infer/lib/python/infer.py +++ b/infer/lib/python/infer.py @@ -157,8 +157,12 @@ def main(): touch_if_present=not args.continue_capture) utils.configure_logging(args) - logging.info('output of locale.getdefaultlocale(): %s', - str(locale.getdefaultlocale())) + try: + logging.info('output of locale.getdefaultlocale(): %s', + str(locale.getdefaultlocale())) + except (locale.Error, ValueError) as e: + logging.info('locale.getdefaultlocale() failed with exception: %s', + str(e)) logging.info('encoding we chose in the end: %s', config.CODESET) logging.info('Running command %s',