Reraise exception in bootstrap_mic() but keep original traceback.
authorHuang Hao <hao.h.huang@intel.com>
Thu, 28 Feb 2013 12:51:44 +0000 (20:51 +0800)
committerHuang Hao <hao.h.huang@intel.com>
Mon, 11 Mar 2013 08:02:43 +0000 (16:02 +0800)
When exception occurs, we could add additional information but
should keep the original traceback. Otherwise traceback shows up
in console will be the second one, which hide the true exception.

A bare "raise" statement is a special syntax to reraise the
original exception, which will also keep its traceback.

Please Refer PEP3134 for more details.

Change-Id: I420399061de89b911cecd5da60fde0023f1893ac

mic/bootstrap.py
mic/rt_util.py

index 598dcbf..9a433a1 100644 (file)
@@ -264,8 +264,11 @@ class Bootstrap(object):
             sync_timesetting(rootdir)
             sync_passwdfile(rootdir)
             retcode = subprocess.call(cmd, preexec_fn=mychroot, env=env, shell=shell)
-        except (OSError, IOError), err:
-            raise RuntimeError(err)
+        except (OSError, IOError):
+            # add additional information to original exception
+            value, tb = sys.exc_info()[1:]
+            value = '%s: %s' % (value, ' '.join(cmd))
+            raise RuntimeError, value, tb
         finally:
             if self.logfile and os.path.isfile(self.logfile):
                 msger.log(file(self.logfile).read())
index 334d757..247c456 100644 (file)
@@ -86,10 +86,11 @@ def bootstrap_mic(argv=None):
         msger.warning('\n%s' % err)
         if msger.ask("Switch to native mode and continue?"):
             return
-        else:
-            raise errors.BootstrapError("Failed to create bootstrap: %s" % err)
+        raise
     except RuntimeError, err:
-        raise errors.BootstrapError("Failed to run in bootstrap: %s" % err)
+        #change exception type but keep the trace back
+        value, tb = sys.exc_info()[1:]
+        raise errors.BootstrapError, value, tb
     else:
         sys.exit(ret)
     finally: