Add filename information to ParseError exception.
Closes #413
diff --git a/CHANGELOG b/CHANGELOG
index 9440470..73bd2e5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@
# This project adheres to [Semantic Versioning](http://semver.org/).
## [0.16.2] 2017-05-19
+### Changed
+- Add filename information to a ParseError excetion.
### Fixed
- Treat expansion operators ('*', '**') in a similar way to function calls to
avoid splitting directly after the opening parenthesis.
@@ -13,16 +15,13 @@
- Split before a function call in a list if the full list isn't able to fit on
a single line.
- Trying not to split around the '=' of a named assign.
-<<<<<<< HEAD
+- Changed split before the first argument behavior to ignore compound
+ statements like if and while, but not function declarations.
+- Changed coalesce brackets not to line split before closing bracket.
- A token that ends in a continuation marker may have more than one newline in
it, thus changing its "lineno" value. This can happen if multiple
continuation markers are used with no intervening tokens. Adjust the line
number to account for the lines covered by those markers.
-=======
-- Changed split before the first argument behavior to ignore compound
- statements like if and while, but not function declarations.
-- Changed coalesce brackets not to line split before closing bracket.
->>>>>>> 5683a4c62c710faedcf65142f3636712eaa608e8
## [0.16.1] 2017-03-22
### Changed
diff --git a/yapf/yapflib/yapf_api.py b/yapf/yapflib/yapf_api.py
index dd91849..f0922c2 100644
--- a/yapf/yapflib/yapf_api.py
+++ b/yapf/yapflib/yapf_api.py
@@ -36,6 +36,7 @@
import re
import sys
+from lib2to3.pgen2 import parse
from lib2to3.pgen2 import tokenize
from yapf.yapflib import blank_line_calculator
@@ -123,7 +124,11 @@
style.SetGlobalStyle(style.CreateStyleFromConfig(style_config))
if not unformatted_source.endswith('\n'):
unformatted_source += '\n'
- tree = pytree_utils.ParseCodeToTree(unformatted_source)
+
+ try:
+ tree = pytree_utils.ParseCodeToTree(unformatted_source)
+ except parse.ParseError as e:
+ raise parse.ParseError(filename + ': ' + e.message)
# Run passes on the tree, modifying it in place.
comment_splicer.SpliceComments(tree)