summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamara Dahlgren <dahlgren1@llnl.gov>2019-06-05 17:23:40 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2019-06-05 22:41:28 -0700
commit8e3fd3f7c292030cbde7836fb88c154c450aa879 (patch)
tree02206b658abe5ead8a2934260af7f075e20e7224
parent8c173da4b76c90765f01692285ea699ccd23c197 (diff)
downloadspack-8e3fd3f7c292030cbde7836fb88c154c450aa879.tar.gz
spack-8e3fd3f7c292030cbde7836fb88c154c450aa879.tar.bz2
spack-8e3fd3f7c292030cbde7836fb88c154c450aa879.tar.xz
spack-8e3fd3f7c292030cbde7836fb88c154c450aa879.zip
tty: make tty.* print exception types
- make tty.msg, tty.info, etc. print the exception type and stringified message if the message argument is an exception. - simplify parts of the code that call tty.debug(str(e)) - add extra tty.debug statements in places where exceptions were previously ignored
-rw-r--r--lib/spack/llnl/util/tty/__init__.py6
-rw-r--r--lib/spack/spack/binary_distribution.py13
-rw-r--r--lib/spack/spack/build_systems/autotools.py8
-rw-r--r--lib/spack/spack/cmd/install.py1
-rw-r--r--lib/spack/spack/cmd/mirror.py1
-rw-r--r--lib/spack/spack/cmd/modules/__init__.py1
-rw-r--r--lib/spack/spack/cmd/upload_s3.py6
-rw-r--r--lib/spack/spack/database.py6
-rw-r--r--lib/spack/spack/fetch_strategy.py6
-rw-r--r--lib/spack/spack/main.py4
-rw-r--r--lib/spack/spack/mirror.py1
-rw-r--r--lib/spack/spack/package.py17
-rw-r--r--lib/spack/spack/repo.py6
-rw-r--r--lib/spack/spack/spec.py1
-rw-r--r--lib/spack/spack/stage.py4
15 files changed, 55 insertions, 26 deletions
diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index 383809295a..c02a21d4ec 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -141,6 +141,9 @@ def msg(message, *args, **kwargs):
if not msg_enabled():
return
+ if isinstance(message, Exception):
+ message = "%s: %s" % (message.__class__.__name__, str(message))
+
newline = kwargs.get('newline', True)
st_text = ""
if _stacktrace:
@@ -156,6 +159,9 @@ def msg(message, *args, **kwargs):
def info(message, *args, **kwargs):
+ if isinstance(message, Exception):
+ message = "%s: %s" % (message.__class__.__name__, str(message))
+
format = kwargs.get('format', '*b')
stream = kwargs.get('stream', sys.stdout)
wrap = kwargs.get('wrap', False)
diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index 602e9605de..bae8edd884 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -321,7 +321,7 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,
# create info for later relocation and create tar
write_buildinfo_file(spec.prefix, workdir, rel=rel)
- # optinally make the paths in the binaries relative to each other
+ # optionally make the paths in the binaries relative to each other
# in the spack install tree before creating tarball
if rel:
try:
@@ -329,14 +329,14 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,
except Exception as e:
shutil.rmtree(workdir)
shutil.rmtree(tarfile_dir)
- tty.die(str(e))
+ tty.die(e)
else:
try:
make_package_placeholder(workdir, spec.prefix, allow_root)
except Exception as e:
shutil.rmtree(workdir)
shutil.rmtree(tarfile_dir)
- tty.die(str(e))
+ tty.die(e)
# create compressed tarball of the install prefix
with closing(tarfile.open(tarfile_path, 'w:gz')) as tar:
tar.add(name='%s' % workdir,
@@ -521,7 +521,7 @@ def extract_tarball(spec, filename, allow_root=False, unsigned=False,
Gpg.verify('%s.asc' % specfile_path, specfile_path)
except Exception as e:
shutil.rmtree(tmpdir)
- tty.die(str(e))
+ tty.die(e)
else:
shutil.rmtree(tmpdir)
raise NoVerifyException(
@@ -575,7 +575,7 @@ def extract_tarball(spec, filename, allow_root=False, unsigned=False,
relocate_package(workdir, allow_root)
except Exception as e:
shutil.rmtree(workdir)
- tty.die(str(e))
+ tty.die(e)
# Delay creating spec.prefix until verification is complete
# and any relocation has been done.
else:
@@ -809,7 +809,8 @@ def _download_buildcache_entry(mirror_root, descriptions):
try:
stage.fetch()
- except fs.FetchError:
+ except fs.FetchError as e:
+ tty.debug(e)
if fail_if_missing:
tty.error('Failed to download required url {0}'.format(url))
return False
diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py
index 3673fb7cce..cd6cfd94bd 100644
--- a/lib/spack/spack/build_systems/autotools.py
+++ b/lib/spack/spack/build_systems/autotools.py
@@ -113,8 +113,8 @@ class AutotoolsPackage(PackageBase):
check_call([my_config_guess], stdout=PIPE, stderr=PIPE)
# The package's config.guess already runs OK, so just use it
return
- except Exception:
- pass
+ except Exception as e:
+ tty.debug(e)
else:
return
@@ -142,8 +142,8 @@ class AutotoolsPackage(PackageBase):
os.chmod(my_config_guess, mod)
shutil.copyfile(config_guess, my_config_guess)
return
- except Exception:
- pass
+ except Exception as e:
+ tty.debug(e)
raise RuntimeError('Failed to find suitable config.guess')
diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py
index 91618fcfd9..9fd7c5b2d3 100644
--- a/lib/spack/spack/cmd/install.py
+++ b/lib/spack/spack/cmd/install.py
@@ -262,6 +262,7 @@ def install(parser, args, **kwargs):
specs = spack.cmd.parse_specs(
args.package, concretize=True, tests=tests)
except SpackError as e:
+ tty.debug(e)
reporter.concretization_report(e.message)
raise
diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py
index 126347285f..e6438a28f4 100644
--- a/lib/spack/spack/cmd/mirror.py
+++ b/lib/spack/spack/cmd/mirror.py
@@ -142,6 +142,7 @@ def _read_specs_from_file(filename):
s.package
specs.append(s)
except SpackError as e:
+ tty.debug(e)
tty.die("Parse error in %s, line %d:" % (filename, i + 1),
">>> " + string, str(e))
return specs
diff --git a/lib/spack/spack/cmd/modules/__init__.py b/lib/spack/spack/cmd/modules/__init__.py
index 7fadd73ee0..cb3d8ebd07 100644
--- a/lib/spack/spack/cmd/modules/__init__.py
+++ b/lib/spack/spack/cmd/modules/__init__.py
@@ -304,6 +304,7 @@ def refresh(module_type, specs, args):
try:
x.write(overwrite=True)
except Exception as e:
+ tty.debug(e)
msg = 'Could not write module file [{0}]'
tty.warn(msg.format(x.layout.filename))
tty.warn('\t--> {0} <--'.format(str(e)))
diff --git a/lib/spack/spack/cmd/upload_s3.py b/lib/spack/spack/cmd/upload_s3.py
index ba3f0688ae..9894341efe 100644
--- a/lib/spack/spack/cmd/upload_s3.py
+++ b/lib/spack/spack/cmd/upload_s3.py
@@ -158,7 +158,8 @@ def upload_spec(args):
try:
spec = Spec(args.spec)
spec.concretize()
- except Exception:
+ except Exception as e:
+ tty.debug(e)
tty.error('Unable to concrectize spec from string {0}'.format(
args.spec))
sys.exit(1)
@@ -166,7 +167,8 @@ def upload_spec(args):
try:
with open(args.spec_yaml, 'r') as fd:
spec = Spec.from_yaml(fd.read())
- except Exception:
+ except Exception as e:
+ tty.debug(e)
tty.error('Unable to concrectize spec from yaml {0}'.format(
args.spec_yaml))
sys.exit(1)
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index b7adae18fb..ad6475b026 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -606,8 +606,7 @@ class Database(object):
except Exception as e:
# Something went wrong, so the spec was not restored
# from old data
- tty.debug(e.message)
- pass
+ tty.debug(e)
self._check_ref_counts()
@@ -659,7 +658,8 @@ class Database(object):
with open(temp_file, 'w') as f:
self._write_to_file(f)
os.rename(temp_file, self._index_path)
- except BaseException:
+ except BaseException as e:
+ tty.debug(e)
# Clean up temp file if something goes wrong.
if os.path.exists(temp_file):
os.remove(temp_file)
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index dd7ebd248b..507aeae1b6 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -1082,11 +1082,13 @@ def from_list_url(pkg):
# construct a fetcher
return URLFetchStrategy(url_from_list, checksum)
- except KeyError:
+ except KeyError as e:
+ tty.debug(e)
tty.msg("Cannot find version %s in url_list" % pkg.version)
- except BaseException:
+ except BaseException as e:
# TODO: Don't catch BaseException here! Be more specific.
+ tty.debug(e)
tty.msg("Could not determine url from list_url.")
diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py
index 9b2e5f1bc6..9c84c2fb19 100644
--- a/lib/spack/spack/main.py
+++ b/lib/spack/spack/main.py
@@ -505,6 +505,7 @@ class SpackCommand(object):
self.returncode = e.code
except BaseException as e:
+ tty.debug(e)
self.error = e
if fail_on_error:
raise
@@ -695,12 +696,13 @@ def main(argv=None):
return _invoke_command(command, parser, args, unknown)
except SpackError as e:
+ tty.debug(e)
e.die() # gracefully die on any SpackErrors
except Exception as e:
if spack.config.get('config:debug'):
raise
- tty.die(str(e))
+ tty.die(e)
except KeyboardInterrupt:
sys.stderr.write('\n')
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py
index f8e795ed56..6d5b2b6c4f 100644
--- a/lib/spack/spack/mirror.py
+++ b/lib/spack/spack/mirror.py
@@ -218,6 +218,7 @@ def add_single_spec(spec, mirror_root, categories, **kwargs):
spec.package.do_clean()
except Exception as e:
+ tty.debug(e)
if spack.config.get('config:debug'):
sys.excepthook(*sys.exc_info())
else:
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 226e0d1643..4cca72c6cf 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1067,7 +1067,9 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
patch.apply(self.stage)
tty.msg('Applied patch %s' % patch.path_or_url)
patched = True
- except spack.error.SpackError:
+ except spack.error.SpackError as e:
+ tty.debug(e)
+
# Touch bad file if anything goes wrong.
tty.msg('Patch %s failed.' % patch.path_or_url)
touch(bad_file)
@@ -1088,7 +1090,10 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
# no patches are needed. Otherwise, we already
# printed a message for each patch.
tty.msg("No patches needed for %s" % self.name)
- except spack.error.SpackError:
+ except spack.error.SpackError as e:
+ tty.debug(e)
+
+ # Touch bad file if anything goes wrong.
tty.msg("patch() function failed for %s" % self.name)
touch(bad_file)
raise
@@ -1724,9 +1729,9 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
try:
# log_install_path and env_install_path are inside this
shutil.rmtree(packages_dir)
- except Exception:
+ except Exception as e:
# FIXME : this potentially catches too many things...
- pass
+ tty.debug(e)
# Archive the whole stdout + stderr for the package
install(self.log_path, log_install_path)
@@ -1762,7 +1767,9 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
# copying a file in
mkdirp(os.path.dirname(target))
install(f, target)
- except Exception:
+ except Exception as e:
+ tty.debug(e)
+
# Here try to be conservative, and avoid discarding
# the whole install procedure because of copying a
# single file failed
diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py
index 7a2e235a4e..1e593634b9 100644
--- a/lib/spack/spack/repo.py
+++ b/lib/spack/spack/repo.py
@@ -893,8 +893,10 @@ class Repo(object):
except spack.error.SpackError:
# pass these through as their error messages will be fine.
raise
- except Exception:
- # make sure other errors in constructors hit the error
+ except Exception as e:
+ tty.debug(e)
+
+ # Make sure other errors in constructors hit the error
# handler by wrapping them
if spack.config.get('config:debug'):
sys.excepthook(*sys.exc_info())
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 0412465ba0..c08d074415 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1723,6 +1723,7 @@ class Spec(object):
data = sjson.load(stream)
return Spec.from_dict(data)
except Exception as e:
+ tty.debug(e)
raise sjson.SpackJSONError("error parsing JSON spec:", str(e))
def _concretize_helper(self, presets=None, visited=None):
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index fb0df21e6f..eb6195a911 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -490,7 +490,8 @@ class Stage(object):
# Make sure we don't end up in a removed directory
try:
os.getcwd()
- except OSError:
+ except OSError as e:
+ tty.debug(e)
os.chdir(os.path.dirname(self.path))
# mark as destroyed
@@ -530,6 +531,7 @@ class ResourceStage(Stage):
try:
os.makedirs(target_path)
except OSError as err:
+ tty.debug(err)
if err.errno == errno.EEXIST and os.path.isdir(target_path):
pass
else: