Unify the YAPF exceptions

There are many potential exceptions that can be generated. Unify them
into a single YapfError with a standardized error message format.
diff --git a/yapf/__init__.py b/yapf/__init__.py
index 4fe2ddf..21eaa01 100644
--- a/yapf/__init__.py
+++ b/yapf/__init__.py
@@ -109,8 +109,8 @@
           style_config=style_config,
           lines=lines,
           verify=args.verify)
-    except tokenize.TokenError as e:
-      raise errors.YapfError('%s:%s' % (e.args[1][0], e.args[0]))
+    except Exception as e:
+      raise errors.YapfError(errors.FormatErrorMsg(e))
 
     file_resources.WriteReformattedCode('<stdout>', reformatted_source)
     return 0
@@ -123,7 +123,7 @@
                                              (args.exclude or []) +
                                              exclude_patterns_from_ignore_file)
   if not files:
-    raise errors.YapfError('Input filenames did not match any python files')
+    raise errors.YapfError('input filenames did not match any python files')
 
   changed = FormatFiles(
       files,
@@ -234,11 +234,10 @@
         print_diff=print_diff,
         verify=verify,
         logger=logging.warning)
-  except tokenize.TokenError as e:
-    raise errors.YapfError('%s:%s:%s' % (filename, e.args[1][0], e.args[0]))
-  except SyntaxError as e:
-    e.filename = filename
+  except errors.YapfError:
     raise
+  except Exception as e:
+    raise errors.YapfError(errors.FormatErrorMsg(e))
 
   if not in_place and not quiet and reformatted_code:
     file_resources.WriteReformattedCode(filename, reformatted_code, encoding,
diff --git a/yapf/yapflib/errors.py b/yapf/yapflib/errors.py
index 3946275..5726ff1 100644
--- a/yapf/yapflib/errors.py
+++ b/yapf/yapflib/errors.py
@@ -11,7 +11,23 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-"""YAPF error object."""
+"""YAPF error objects."""
+
+
+def FormatErrorMsg(e):
+  """Convert an exception into a standard format.
+
+  The standard error message format is:
+
+      <filename>:<lineno>:<column>: <msg>
+
+  Arguments:
+    e: An exception.
+
+  Returns:
+    A properly formatted error message string.
+  """
+  return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
 
 
 class YapfError(Exception):
diff --git a/yapf/yapflib/yapf_api.py b/yapf/yapflib/yapf_api.py
index 0ef2a1e..ac0466e 100644
--- a/yapf/yapflib/yapf_api.py
+++ b/yapf/yapflib/yapf_api.py
@@ -37,10 +37,12 @@
 import sys
 
 from lib2to3.pgen2 import parse
+from lib2to3.pgen2 import tokenize
 
 from yapf.yapflib import blank_line_calculator
 from yapf.yapflib import comment_splicer
 from yapf.yapflib import continuation_splicer
+from yapf.yapflib import errors
 from yapf.yapflib import file_resources
 from yapf.yapflib import identify_container
 from yapf.yapflib import py3compat
@@ -179,8 +181,12 @@
   """
   try:
     tree = pytree_utils.ParseCodeToTree(unformatted_source)
-  except parse.ParseError as e:
-    e.msg = filename + ': ' + e.msg
+  except tokenize.TokenError as e:
+    e.msg = e.args[0]
+    e.args = (e.msg, (filename, e.args[1][0], e.args[1][1]))
+    raise
+  except Exception as e:
+    e.args = (e.args[0], (filename, e.args[1][1], e.args[1][2], e.args[1][3]))
     raise
 
   reformatted_source = FormatTree(
@@ -236,15 +242,17 @@
     line_ending = file_resources.LineEnding(lines)
     source = '\n'.join(line.rstrip('\r\n') for line in lines) + '\n'
     return source, line_ending, encoding
-  except IOError as err:  # pragma: no cover
+  except IOError as e:  # pragma: no cover
     if logger:
-      logger(err)
+      logger(e)
+    e.args = (e.args[0], (filename, e.args[1][1], e.args[1][2], e.args[1][3]))
     raise
-  except UnicodeDecodeError as err:  # pragma: no cover
+  except UnicodeDecodeError as e:  # pragma: no cover
     if logger:
       logger('Could not parse %s! Consider excluding this file with --exclude.',
              filename)
-      logger(err)
+      logger(e)
+    e.args = (e.args[0], (filename, e.args[1][1], e.args[1][2], e.args[1][3]))
     raise
 
 
diff --git a/yapftests/main_test.py b/yapftests/main_test.py
index a9069b0..dd89753 100644
--- a/yapftests/main_test.py
+++ b/yapftests/main_test.py
@@ -89,7 +89,7 @@
 
   def testShouldHandleYapfError(self):
     """run_main should handle YapfError and sys.exit(1)."""
-    expected_message = 'yapf: Input filenames did not match any python files\n'
+    expected_message = 'yapf: input filenames did not match any python files\n'
     sys.argv = ['yapf', 'foo.c']
     with captured_output() as (out, err):
       with self.assertRaises(SystemExit):
@@ -126,7 +126,7 @@
     bad_syntax = '  a = 1\n'
     with patched_input(bad_syntax):
       with captured_output() as (_, _):
-        with self.assertRaisesRegex(SyntaxError, 'unexpected indent'):
+        with self.assertRaisesRegex(yapf.errors.YapfError, 'unexpected indent'):
           yapf.main([])
 
   def testHelp(self):