diff --git a/CHANGELOG b/CHANGELOG index 4996e6b25..c7bdc762e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,7 @@ ### Changed - Set `INDENT_DICTIONARY_VALUE` for Google style. - Set `JOIN_MULTIPLE_LINES = False` for Google style. +- Catch and report `UnicodeDecodeError` exceptions. ### Fixed - `BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False` wasn't honored because the number of newlines was erroneously calculated beforehand. diff --git a/yapf/yapflib/yapf_api.py b/yapf/yapflib/yapf_api.py index 282dea3eb..f5240abce 100644 --- a/yapf/yapflib/yapf_api.py +++ b/yapf/yapflib/yapf_api.py @@ -202,6 +202,12 @@ def ReadFile(filename, logger=None): if logger: logger(err) raise + except UnicodeDecodeError as err: # pragma: no cover + if logger: + logger('Could not parse %s! Consider excluding this file with --exclude.', + filename) + logger(err) + raise def _SplitSemicolons(uwlines):