[Mpuls-commits] r5397 - base/trunk/mpulsweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 27 20:26:11 CEST 2011


Author: bh
Date: 2011-09-27 20:26:10 +0200 (Tue, 27 Sep 2011)
New Revision: 5397

Modified:
   base/trunk/mpulsweb/model/meta.py
Log:
Raise an exception if XSLT conversion for the meta-case upload fails.#
Previously convert_meta_xml would simply log an error and return None if
the sub-process failed, but the callers do not check for this which
leads to errors later that are harder to debug.


Modified: base/trunk/mpulsweb/model/meta.py
===================================================================
--- base/trunk/mpulsweb/model/meta.py	2011-09-27 14:20:23 UTC (rev 5396)
+++ base/trunk/mpulsweb/model/meta.py	2011-09-27 18:26:10 UTC (rev 5397)
@@ -47,14 +47,29 @@
                       user.login)
 
 
+class SubprocessError(EnvironmentError):
+
+    def __init__(self, command, returncode):
+        EnvironmentError.__init__(self,
+                                  "Command %r finished with return code %d"
+                                  % (command, returncode))
+        self.returncode = returncode
+
+
 def convert_meta_xml(converter, project_xml):
-    proc = subprocess.Popen(["xsltproc", converter, "-"], stdin=subprocess.PIPE,
+    command = ["xsltproc", converter, "-"]
+    proc = subprocess.Popen(command, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     out, err = proc.communicate(project_xml)
 
     if proc.returncode != 0:
         log.error("Error running xsltproc subprocess: %r", err)
-        return None
+        # The exception raised here is not derived from MetaException
+        # because calling xsltproc should only fail because of
+        # programming errors and therefore it's better to let the
+        # web-application return an internal server error than to show a
+        # specific error message as would happen with MetaException.
+        raise SubprocessError(command, proc.returncode)
     if err:
         log.warning("Unexpected stderr output of xsltproc: %r", err)
 



More information about the Mpuls-commits mailing list