Improve clang-format error messages when run outside of chromium checkout

Its useful to be able to run clang-format on projects
outside of chromium. This change informs developers
how they can do that.

Change-Id: I01ef755aa6e5b53a0a5bb6377e92b2ffdfd17eff
Reviewed-on: https://chromium-review.googlesource.com/414204
Reviewed-by: Aaron Gable <agable@chromium.org>
Commit-Queue: Sam Clegg <sbc@chromium.org>
diff --git a/clang_format.py b/clang_format.py
index 5bfeb1a..804a205 100755
--- a/clang_format.py
+++ b/clang_format.py
@@ -20,7 +20,7 @@
   def __init__(self, e):
     Exception.__init__(self,
         'Problem while looking for clang-format in Chromium source tree:\n'
-        '  %s' % e)
+        '%s' % e)
 
 
 def FindClangFormatToolInChromiumTree():
@@ -28,7 +28,8 @@
   bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()
   if not bin_path:
     raise NotFoundError(
-        'Could not find checkout in any parent of the current path.')
+        'Could not find checkout in any parent of the current path.\n'
+        'Set CHROMIUM_BUILDTOOLS_PATH to use outside of a chromium checkout.')
 
   tool_path = os.path.join(bin_path,
                            'clang-format' + gclient_utils.GetExeSuffix())
@@ -42,7 +43,9 @@
   tools_path = gclient_utils.GetBuildtoolsPath()
   if not tools_path:
     raise NotFoundError(
-        'Could not find checkout in any parent of the current path.')
+        'Could not find checkout in any parent of the current path.\n',
+        'Set CHROMIUM_BUILDTOOLS_PATH to use outside of a chromium checkout.')
+
   script_path = os.path.join(tools_path, 'clang_format', 'script', script_name)
   if not os.path.exists(script_path):
     raise NotFoundError('File does not exist: %s' % script_path)
@@ -52,9 +55,9 @@
 def main(args):
   try:
     tool = FindClangFormatToolInChromiumTree()
-  except NotFoundError, e:
-    print >> sys.stderr, e
-    sys.exit(1)
+  except NotFoundError as e:
+    sys.stderr.write("%s\n" % str(e))
+    return 1
 
   # Add some visibility to --help showing where the tool lives, since this
   # redirection can be a little opaque.