diff options
Diffstat (limited to 'yapf/yapflib/errors.py')
-rw-r--r-- | yapf/yapflib/errors.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/yapf/yapflib/errors.py b/yapf/yapflib/errors.py index 5726ff1..99e88d9 100644 --- a/yapf/yapflib/errors.py +++ b/yapf/yapflib/errors.py @@ -13,6 +13,8 @@ # limitations under the License. """YAPF error objects.""" +from lib2to3.pgen2 import tokenize + def FormatErrorMsg(e): """Convert an exception into a standard format. @@ -27,6 +29,11 @@ def FormatErrorMsg(e): Returns: A properly formatted error message string. """ + if isinstance(e, SyntaxError): + return '{}:{}:{}: {}'.format(e.filename, e.lineno, e.offset, e.msg) + if isinstance(e, tokenize.TokenError): + return '{}:{}:{}: {}'.format(e.filename, e.args[1][0], e.args[1][1], + e.args[0]) return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg) |