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
This commit is contained in:
parent
8c173da4b7
commit
8e3fd3f7c2
@ -141,6 +141,9 @@ def msg(message, *args, **kwargs):
|
|||||||
if not msg_enabled():
|
if not msg_enabled():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if isinstance(message, Exception):
|
||||||
|
message = "%s: %s" % (message.__class__.__name__, str(message))
|
||||||
|
|
||||||
newline = kwargs.get('newline', True)
|
newline = kwargs.get('newline', True)
|
||||||
st_text = ""
|
st_text = ""
|
||||||
if _stacktrace:
|
if _stacktrace:
|
||||||
@ -156,6 +159,9 @@ def msg(message, *args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def info(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')
|
format = kwargs.get('format', '*b')
|
||||||
stream = kwargs.get('stream', sys.stdout)
|
stream = kwargs.get('stream', sys.stdout)
|
||||||
wrap = kwargs.get('wrap', False)
|
wrap = kwargs.get('wrap', False)
|
||||||
|
@ -321,7 +321,7 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,
|
|||||||
# create info for later relocation and create tar
|
# create info for later relocation and create tar
|
||||||
write_buildinfo_file(spec.prefix, workdir, rel=rel)
|
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
|
# in the spack install tree before creating tarball
|
||||||
if rel:
|
if rel:
|
||||||
try:
|
try:
|
||||||
@ -329,14 +329,14 @@ def build_tarball(spec, outdir, force=False, rel=False, unsigned=False,
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
shutil.rmtree(workdir)
|
shutil.rmtree(workdir)
|
||||||
shutil.rmtree(tarfile_dir)
|
shutil.rmtree(tarfile_dir)
|
||||||
tty.die(str(e))
|
tty.die(e)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
make_package_placeholder(workdir, spec.prefix, allow_root)
|
make_package_placeholder(workdir, spec.prefix, allow_root)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
shutil.rmtree(workdir)
|
shutil.rmtree(workdir)
|
||||||
shutil.rmtree(tarfile_dir)
|
shutil.rmtree(tarfile_dir)
|
||||||
tty.die(str(e))
|
tty.die(e)
|
||||||
# create compressed tarball of the install prefix
|
# create compressed tarball of the install prefix
|
||||||
with closing(tarfile.open(tarfile_path, 'w:gz')) as tar:
|
with closing(tarfile.open(tarfile_path, 'w:gz')) as tar:
|
||||||
tar.add(name='%s' % workdir,
|
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)
|
Gpg.verify('%s.asc' % specfile_path, specfile_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
tty.die(str(e))
|
tty.die(e)
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
raise NoVerifyException(
|
raise NoVerifyException(
|
||||||
@ -575,7 +575,7 @@ def extract_tarball(spec, filename, allow_root=False, unsigned=False,
|
|||||||
relocate_package(workdir, allow_root)
|
relocate_package(workdir, allow_root)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
shutil.rmtree(workdir)
|
shutil.rmtree(workdir)
|
||||||
tty.die(str(e))
|
tty.die(e)
|
||||||
# Delay creating spec.prefix until verification is complete
|
# Delay creating spec.prefix until verification is complete
|
||||||
# and any relocation has been done.
|
# and any relocation has been done.
|
||||||
else:
|
else:
|
||||||
@ -809,7 +809,8 @@ def _download_buildcache_entry(mirror_root, descriptions):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
stage.fetch()
|
stage.fetch()
|
||||||
except fs.FetchError:
|
except fs.FetchError as e:
|
||||||
|
tty.debug(e)
|
||||||
if fail_if_missing:
|
if fail_if_missing:
|
||||||
tty.error('Failed to download required url {0}'.format(url))
|
tty.error('Failed to download required url {0}'.format(url))
|
||||||
return False
|
return False
|
||||||
|
@ -113,8 +113,8 @@ def _do_patch_config_guess(self):
|
|||||||
check_call([my_config_guess], stdout=PIPE, stderr=PIPE)
|
check_call([my_config_guess], stdout=PIPE, stderr=PIPE)
|
||||||
# The package's config.guess already runs OK, so just use it
|
# The package's config.guess already runs OK, so just use it
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
tty.debug(e)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -142,8 +142,8 @@ def _do_patch_config_guess(self):
|
|||||||
os.chmod(my_config_guess, mod)
|
os.chmod(my_config_guess, mod)
|
||||||
shutil.copyfile(config_guess, my_config_guess)
|
shutil.copyfile(config_guess, my_config_guess)
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
tty.debug(e)
|
||||||
|
|
||||||
raise RuntimeError('Failed to find suitable config.guess')
|
raise RuntimeError('Failed to find suitable config.guess')
|
||||||
|
|
||||||
|
@ -262,6 +262,7 @@ def install(parser, args, **kwargs):
|
|||||||
specs = spack.cmd.parse_specs(
|
specs = spack.cmd.parse_specs(
|
||||||
args.package, concretize=True, tests=tests)
|
args.package, concretize=True, tests=tests)
|
||||||
except SpackError as e:
|
except SpackError as e:
|
||||||
|
tty.debug(e)
|
||||||
reporter.concretization_report(e.message)
|
reporter.concretization_report(e.message)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -142,6 +142,7 @@ def _read_specs_from_file(filename):
|
|||||||
s.package
|
s.package
|
||||||
specs.append(s)
|
specs.append(s)
|
||||||
except SpackError as e:
|
except SpackError as e:
|
||||||
|
tty.debug(e)
|
||||||
tty.die("Parse error in %s, line %d:" % (filename, i + 1),
|
tty.die("Parse error in %s, line %d:" % (filename, i + 1),
|
||||||
">>> " + string, str(e))
|
">>> " + string, str(e))
|
||||||
return specs
|
return specs
|
||||||
|
@ -304,6 +304,7 @@ def refresh(module_type, specs, args):
|
|||||||
try:
|
try:
|
||||||
x.write(overwrite=True)
|
x.write(overwrite=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
tty.debug(e)
|
||||||
msg = 'Could not write module file [{0}]'
|
msg = 'Could not write module file [{0}]'
|
||||||
tty.warn(msg.format(x.layout.filename))
|
tty.warn(msg.format(x.layout.filename))
|
||||||
tty.warn('\t--> {0} <--'.format(str(e)))
|
tty.warn('\t--> {0} <--'.format(str(e)))
|
||||||
|
@ -158,7 +158,8 @@ def upload_spec(args):
|
|||||||
try:
|
try:
|
||||||
spec = Spec(args.spec)
|
spec = Spec(args.spec)
|
||||||
spec.concretize()
|
spec.concretize()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
tty.debug(e)
|
||||||
tty.error('Unable to concrectize spec from string {0}'.format(
|
tty.error('Unable to concrectize spec from string {0}'.format(
|
||||||
args.spec))
|
args.spec))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -166,7 +167,8 @@ def upload_spec(args):
|
|||||||
try:
|
try:
|
||||||
with open(args.spec_yaml, 'r') as fd:
|
with open(args.spec_yaml, 'r') as fd:
|
||||||
spec = Spec.from_yaml(fd.read())
|
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(
|
tty.error('Unable to concrectize spec from yaml {0}'.format(
|
||||||
args.spec_yaml))
|
args.spec_yaml))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -606,8 +606,7 @@ def _construct_from_directory_layout(self, directory_layout, old_data):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Something went wrong, so the spec was not restored
|
# Something went wrong, so the spec was not restored
|
||||||
# from old data
|
# from old data
|
||||||
tty.debug(e.message)
|
tty.debug(e)
|
||||||
pass
|
|
||||||
|
|
||||||
self._check_ref_counts()
|
self._check_ref_counts()
|
||||||
|
|
||||||
@ -659,7 +658,8 @@ def _write(self, type, value, traceback):
|
|||||||
with open(temp_file, 'w') as f:
|
with open(temp_file, 'w') as f:
|
||||||
self._write_to_file(f)
|
self._write_to_file(f)
|
||||||
os.rename(temp_file, self._index_path)
|
os.rename(temp_file, self._index_path)
|
||||||
except BaseException:
|
except BaseException as e:
|
||||||
|
tty.debug(e)
|
||||||
# Clean up temp file if something goes wrong.
|
# Clean up temp file if something goes wrong.
|
||||||
if os.path.exists(temp_file):
|
if os.path.exists(temp_file):
|
||||||
os.remove(temp_file)
|
os.remove(temp_file)
|
||||||
|
@ -1082,11 +1082,13 @@ def from_list_url(pkg):
|
|||||||
|
|
||||||
# construct a fetcher
|
# construct a fetcher
|
||||||
return URLFetchStrategy(url_from_list, checksum)
|
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)
|
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.
|
# TODO: Don't catch BaseException here! Be more specific.
|
||||||
|
tty.debug(e)
|
||||||
tty.msg("Could not determine url from list_url.")
|
tty.msg("Could not determine url from list_url.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -505,6 +505,7 @@ def __call__(self, *argv, **kwargs):
|
|||||||
self.returncode = e.code
|
self.returncode = e.code
|
||||||
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
tty.debug(e)
|
||||||
self.error = e
|
self.error = e
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise
|
raise
|
||||||
@ -695,12 +696,13 @@ def main(argv=None):
|
|||||||
return _invoke_command(command, parser, args, unknown)
|
return _invoke_command(command, parser, args, unknown)
|
||||||
|
|
||||||
except SpackError as e:
|
except SpackError as e:
|
||||||
|
tty.debug(e)
|
||||||
e.die() # gracefully die on any SpackErrors
|
e.die() # gracefully die on any SpackErrors
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if spack.config.get('config:debug'):
|
if spack.config.get('config:debug'):
|
||||||
raise
|
raise
|
||||||
tty.die(str(e))
|
tty.die(e)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.stderr.write('\n')
|
sys.stderr.write('\n')
|
||||||
|
@ -218,6 +218,7 @@ def add_single_spec(spec, mirror_root, categories, **kwargs):
|
|||||||
spec.package.do_clean()
|
spec.package.do_clean()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
tty.debug(e)
|
||||||
if spack.config.get('config:debug'):
|
if spack.config.get('config:debug'):
|
||||||
sys.excepthook(*sys.exc_info())
|
sys.excepthook(*sys.exc_info())
|
||||||
else:
|
else:
|
||||||
|
@ -1067,7 +1067,9 @@ def do_patch(self):
|
|||||||
patch.apply(self.stage)
|
patch.apply(self.stage)
|
||||||
tty.msg('Applied patch %s' % patch.path_or_url)
|
tty.msg('Applied patch %s' % patch.path_or_url)
|
||||||
patched = True
|
patched = True
|
||||||
except spack.error.SpackError:
|
except spack.error.SpackError as e:
|
||||||
|
tty.debug(e)
|
||||||
|
|
||||||
# Touch bad file if anything goes wrong.
|
# Touch bad file if anything goes wrong.
|
||||||
tty.msg('Patch %s failed.' % patch.path_or_url)
|
tty.msg('Patch %s failed.' % patch.path_or_url)
|
||||||
touch(bad_file)
|
touch(bad_file)
|
||||||
@ -1088,7 +1090,10 @@ def do_patch(self):
|
|||||||
# no patches are needed. Otherwise, we already
|
# no patches are needed. Otherwise, we already
|
||||||
# printed a message for each patch.
|
# printed a message for each patch.
|
||||||
tty.msg("No patches needed for %s" % self.name)
|
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)
|
tty.msg("patch() function failed for %s" % self.name)
|
||||||
touch(bad_file)
|
touch(bad_file)
|
||||||
raise
|
raise
|
||||||
@ -1724,9 +1729,9 @@ def log(self):
|
|||||||
try:
|
try:
|
||||||
# log_install_path and env_install_path are inside this
|
# log_install_path and env_install_path are inside this
|
||||||
shutil.rmtree(packages_dir)
|
shutil.rmtree(packages_dir)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
# FIXME : this potentially catches too many things...
|
# FIXME : this potentially catches too many things...
|
||||||
pass
|
tty.debug(e)
|
||||||
|
|
||||||
# Archive the whole stdout + stderr for the package
|
# Archive the whole stdout + stderr for the package
|
||||||
install(self.log_path, log_install_path)
|
install(self.log_path, log_install_path)
|
||||||
@ -1762,7 +1767,9 @@ def log(self):
|
|||||||
# copying a file in
|
# copying a file in
|
||||||
mkdirp(os.path.dirname(target))
|
mkdirp(os.path.dirname(target))
|
||||||
install(f, target)
|
install(f, target)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
tty.debug(e)
|
||||||
|
|
||||||
# Here try to be conservative, and avoid discarding
|
# Here try to be conservative, and avoid discarding
|
||||||
# the whole install procedure because of copying a
|
# the whole install procedure because of copying a
|
||||||
# single file failed
|
# single file failed
|
||||||
|
@ -893,8 +893,10 @@ def get(self, spec):
|
|||||||
except spack.error.SpackError:
|
except spack.error.SpackError:
|
||||||
# pass these through as their error messages will be fine.
|
# pass these through as their error messages will be fine.
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception as e:
|
||||||
# make sure other errors in constructors hit the error
|
tty.debug(e)
|
||||||
|
|
||||||
|
# Make sure other errors in constructors hit the error
|
||||||
# handler by wrapping them
|
# handler by wrapping them
|
||||||
if spack.config.get('config:debug'):
|
if spack.config.get('config:debug'):
|
||||||
sys.excepthook(*sys.exc_info())
|
sys.excepthook(*sys.exc_info())
|
||||||
|
@ -1723,6 +1723,7 @@ def from_json(stream):
|
|||||||
data = sjson.load(stream)
|
data = sjson.load(stream)
|
||||||
return Spec.from_dict(data)
|
return Spec.from_dict(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
tty.debug(e)
|
||||||
raise sjson.SpackJSONError("error parsing JSON spec:", str(e))
|
raise sjson.SpackJSONError("error parsing JSON spec:", str(e))
|
||||||
|
|
||||||
def _concretize_helper(self, presets=None, visited=None):
|
def _concretize_helper(self, presets=None, visited=None):
|
||||||
|
@ -490,7 +490,8 @@ def destroy(self):
|
|||||||
# Make sure we don't end up in a removed directory
|
# Make sure we don't end up in a removed directory
|
||||||
try:
|
try:
|
||||||
os.getcwd()
|
os.getcwd()
|
||||||
except OSError:
|
except OSError as e:
|
||||||
|
tty.debug(e)
|
||||||
os.chdir(os.path.dirname(self.path))
|
os.chdir(os.path.dirname(self.path))
|
||||||
|
|
||||||
# mark as destroyed
|
# mark as destroyed
|
||||||
@ -530,6 +531,7 @@ def _add_to_root_stage(self):
|
|||||||
try:
|
try:
|
||||||
os.makedirs(target_path)
|
os.makedirs(target_path)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
|
tty.debug(err)
|
||||||
if err.errno == errno.EEXIST and os.path.isdir(target_path):
|
if err.errno == errno.EEXIST and os.path.isdir(target_path):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user