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():
|
||||
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)
|
||||
|
@ -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
|
||||
|
@ -113,8 +113,8 @@ def _do_patch_config_guess(self):
|
||||
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 @@ def _do_patch_config_guess(self):
|
||||
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')
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -606,8 +606,7 @@ def _construct_from_directory_layout(self, directory_layout, old_data):
|
||||
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 @@ def _write(self, type, value, traceback):
|
||||
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)
|
||||
|
@ -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.")
|
||||
|
||||
|
||||
|
@ -505,6 +505,7 @@ def __call__(self, *argv, **kwargs):
|
||||
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')
|
||||
|
@ -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:
|
||||
|
@ -1067,7 +1067,9 @@ def do_patch(self):
|
||||
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 @@ def do_patch(self):
|
||||
# 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 @@ def log(self):
|
||||
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 @@ def log(self):
|
||||
# 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
|
||||
|
@ -893,8 +893,10 @@ def get(self, spec):
|
||||
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())
|
||||
|
@ -1723,6 +1723,7 @@ def from_json(stream):
|
||||
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):
|
||||
|
@ -490,7 +490,8 @@ def destroy(self):
|
||||
# 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 @@ def _add_to_root_stage(self):
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user