summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2015-06-06 15:50:01 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2015-06-06 15:50:01 -0700
commit53feb12ea078cd9661eca2311fdbc18b352ddc37 (patch)
treeb11f0eaedb321af91a0d96932adb72ad689158b1
parentb9746de52e62a6e11fabcd25ec7fbd9dbb9505d6 (diff)
downloadspack-53feb12ea078cd9661eca2311fdbc18b352ddc37.tar.gz
spack-53feb12ea078cd9661eca2311fdbc18b352ddc37.tar.bz2
spack-53feb12ea078cd9661eca2311fdbc18b352ddc37.tar.xz
spack-53feb12ea078cd9661eca2311fdbc18b352ddc37.zip
Cleanup and consolidate error handling
-rwxr-xr-xbin/spack9
-rw-r--r--lib/spack/spack/build_environment.py4
-rw-r--r--lib/spack/spack/error.py15
-rw-r--r--lib/spack/spack/package.py11
4 files changed, 21 insertions, 18 deletions
diff --git a/bin/spack b/bin/spack
index 354754594e..5c042edd2d 100755
--- a/bin/spack
+++ b/bin/spack
@@ -126,14 +126,7 @@ def main():
try:
return_val = command(parser, args)
except SpackError, e:
- if spack.debug:
- # In debug mode, raise with a full stack trace.
- raise
- elif e.long_message:
- tty.die(e.message, e.long_message)
- else:
- tty.die(e.message)
-
+ e.die()
except KeyboardInterrupt:
sys.stderr.write('\n')
tty.die("Keyboard interrupt.")
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index f9e795ac42..81fbedc689 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -280,6 +280,10 @@ def fork(pkg, function):
# Use os._exit here to avoid raising a SystemExit exception,
# which interferes with unit tests.
os._exit(0)
+
+ except spack.error.SpackError, e:
+ e.die()
+
except:
# Child doesn't raise or return to main spack code.
# Just runs default exception handler and exits.
diff --git a/lib/spack/spack/error.py b/lib/spack/spack/error.py
index e8fa756682..bfa7951a47 100644
--- a/lib/spack/spack/error.py
+++ b/lib/spack/spack/error.py
@@ -22,6 +22,10 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
+import os
+import sys
+import llnl.util.tty as tty
+import spack
class SpackError(Exception):
"""This is the superclass for all Spack errors.
@@ -38,6 +42,17 @@ class SpackError(Exception):
return self._long_message
+ def die(self):
+ if spack.debug:
+ sys.excepthook(*sys.exc_info())
+ os._exit(1)
+ else:
+ tty.error(self.message)
+ if self.long_message:
+ print self.long_message
+ os._exit(1)
+
+
def __str__(self):
msg = self.message
if self.long_message:
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 5dd410d0e4..e3d766f582 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -816,17 +816,8 @@ class Package(object):
except ProcessError, e:
# Annotate with location of build log.
e.build_log = log_path
-
- # One of the processes returned an error code.
- # Suppress detailed stack trace here unless in debug mode
- if spack.debug:
- raise e
- else:
- tty.error(e)
-
- # Still need to clean up b/c there was an error.
cleanup()
- os._exit(1)
+ raise e
except:
# other exceptions just clean up and raise.