From 59994bcc3e7a3f16e9380b610aaf1f8afa08aa39 Mon Sep 17 00:00:00 2001
From: Masood Malekghassemi <soltanmm@users.noreply.github.com>
Date: Tue, 12 Jan 2016 08:49:26 -0800
Subject: [PATCH] Warn on Python proto module build failure

---
 src/python/grpcio/commands.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py
index 81dab1b518..6a7df8e1c1 100644
--- a/src/python/grpcio/commands.py
+++ b/src/python/grpcio/commands.py
@@ -51,6 +51,10 @@ html_theme = 'sphinx_rtd_theme'
 """
 
 
+class CommandError(Exception):
+  """Simple exception class for GRPC custom commands."""
+
+
 class SphinxDocumentation(setuptools.Command):
   """Command to generate documentation via sphinx."""
 
@@ -104,10 +108,10 @@ class BuildProtoModules(setuptools.Command):
 
   def run(self):
     if not self.protoc_command:
-      raise Exception('could not find protoc')
+      raise CommandError('could not find protoc')
     if not self.grpc_python_plugin_command:
-      raise Exception('could not find grpc_python_plugin '
-                      '(protoc plugin for GRPC Python)')
+      raise CommandError('could not find grpc_python_plugin '
+                         '(protoc plugin for GRPC Python)')
     include_regex = re.compile(self.include)
     exclude_regex = re.compile(self.exclude) if self.exclude else None
     paths = []
@@ -130,7 +134,7 @@ class BuildProtoModules(setuptools.Command):
       subprocess.check_output(' '.join(command), cwd=root_directory, shell=True,
                               stderr=subprocess.STDOUT)
     except subprocess.CalledProcessError as e:
-      raise Exception('Command:\n{}\nMessage:\n{}\nOutput:\n{}'.format(
+      raise CommandError('Command:\n{}\nMessage:\n{}\nOutput:\n{}'.format(
           command, e.message, e.output))
 
 
@@ -156,9 +160,10 @@ class BuildPy(build_py.build_py):
   """Custom project build command."""
 
   def run(self):
-    # TODO(atash): make this warn if the proto modules couldn't be built rather
-    # than cause build failure
-    self.run_command('build_proto_modules')
+    try:
+      self.run_command('build_proto_modules')
+    except CommandError as error:
+      sys.stderr.write('warning: %s\n' % error.message)
     self.run_command('build_project_metadata')
     build_py.build_py.run(self)
 
-- 
GitLab