Better error messages for spack reindex.

This commit is contained in:
Todd Gamblin 2016-07-18 01:11:24 -07:00
parent c898b9db04
commit cdc2ebee90
2 changed files with 17 additions and 7 deletions

View file

@ -646,6 +646,7 @@ def __init__(self, path, msg=''):
class InvalidDatabaseVersionError(SpackError): class InvalidDatabaseVersionError(SpackError):
def __init__(self, expected, found): def __init__(self, expected, found):
super(InvalidDatabaseVersionError, self).__init__( super(InvalidDatabaseVersionError, self).__init__(
"Expected database version %s but found version %s." + \ "Expected database version %s but found version %s."
"Try running `spack reindex` to fix." % % (expected, found),
(expected, found)) "`spack reindex` may fix this, or you may need a newer "
"Spack version.")

View file

@ -34,6 +34,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.filesystem import join_path, mkdirp from llnl.util.filesystem import join_path, mkdirp
import spack
from spack.spec import Spec from spack.spec import Spec
from spack.error import SpackError from spack.error import SpackError
@ -223,8 +224,14 @@ def write_spec(self, spec, path):
def read_spec(self, path): def read_spec(self, path):
"""Read the contents of a file and parse them as a spec""" """Read the contents of a file and parse them as a spec"""
with open(path) as f: try:
spec = Spec.from_yaml(f) 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 # Specs read from actual installations are always concrete
spec._mark_concrete() spec._mark_concrete()
@ -456,10 +463,12 @@ def __init__(self, path):
"Install path %s already exists!") "Install path %s already exists!")
class SpecReadError(DirectoryLayoutError):
"""Raised when directory layout can't read a spec."""
class InvalidExtensionSpecError(DirectoryLayoutError): class InvalidExtensionSpecError(DirectoryLayoutError):
"""Raised when an extension file has a bad spec in it.""" """Raised when an extension file has a bad spec in it."""
def __init__(self, message):
super(InvalidExtensionSpecError, self).__init__(message)
class ExtensionAlreadyInstalledError(DirectoryLayoutError): class ExtensionAlreadyInstalledError(DirectoryLayoutError):