From cdc2ebee9018cc4cf067d73f269628901a8d4487 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 18 Jul 2016 01:11:24 -0700 Subject: [PATCH] Better error messages for `spack reindex`. --- lib/spack/spack/database.py | 7 ++++--- lib/spack/spack/directory_layout.py | 17 +++++++++++++---- 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 @@ def __init__(self, path, msg=''): 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 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 @@ def write_spec(self, spec, path): 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 @@ def __init__(self, path): "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):