summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-07-18 01:11:24 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-07-18 01:14:47 -0700
commitcdc2ebee9018cc4cf067d73f269628901a8d4487 (patch)
tree95ab7181f89eefddf1f87b7d17fcd82f153bc35b /lib
parentc898b9db04677a801273690d794b8e29919160a3 (diff)
downloadspack-cdc2ebee9018cc4cf067d73f269628901a8d4487.tar.gz
spack-cdc2ebee9018cc4cf067d73f269628901a8d4487.tar.bz2
spack-cdc2ebee9018cc4cf067d73f269628901a8d4487.tar.xz
spack-cdc2ebee9018cc4cf067d73f269628901a8d4487.zip
Better error messages for `spack reindex`.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/database.py7
-rw-r--r--lib/spack/spack/directory_layout.py17
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index c95abd7423..eabf740dbc 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -646,6 +646,7 @@ class CorruptDatabaseError(SpackError):
class InvalidDatabaseVersionError(SpackError):
def __init__(self, expected, found):
super(InvalidDatabaseVersionError, self).__init__(
- "Expected database version %s but found version %s." + \
- "Try running `spack reindex` to fix." %
- (expected, found))
+ "Expected database version %s but found version %s."
+ % (expected, found),
+ "`spack reindex` may fix this, or you may need a newer "
+ "Spack version.")
diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py
index a5e76043ad..8150a6da2b 100644
--- a/lib/spack/spack/directory_layout.py
+++ b/lib/spack/spack/directory_layout.py
@@ -34,6 +34,7 @@ import yaml
import llnl.util.tty as tty
from llnl.util.filesystem import join_path, mkdirp
+import spack
from spack.spec import Spec
from spack.error import SpackError
@@ -223,8 +224,14 @@ class YamlDirectoryLayout(DirectoryLayout):
def read_spec(self, path):
"""Read the contents of a file and parse them as a spec"""
- with open(path) as f:
- spec = Spec.from_yaml(f)
+ try:
+ with open(path) as f:
+ spec = Spec.from_yaml(f)
+ except Exception as e:
+ if spack.debug:
+ raise
+ raise SpecReadError(
+ 'Unable to read file: %s' % path, 'Cause: ' + str(e))
# Specs read from actual installations are always concrete
spec._mark_concrete()
@@ -456,10 +463,12 @@ class InstallDirectoryAlreadyExistsError(DirectoryLayoutError):
"Install path %s already exists!")
+class SpecReadError(DirectoryLayoutError):
+ """Raised when directory layout can't read a spec."""
+
+
class InvalidExtensionSpecError(DirectoryLayoutError):
"""Raised when an extension file has a bad spec in it."""
- def __init__(self, message):
- super(InvalidExtensionSpecError, self).__init__(message)
class ExtensionAlreadyInstalledError(DirectoryLayoutError):