diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 5ed4d9249a..56b96b3a32 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -130,7 +130,7 @@ def groupid_to_group(x): try: for line in fileinput.input(filename, inplace=True): print(re.sub(regex, repl, line.rstrip('\n'))) - except: + except BaseException: # clean up the original file on failure. shutil.move(backup_filename, filename) raise diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py index ac51d201aa..5668f73388 100644 --- a/lib/spack/llnl/util/tty/__init__.py +++ b/lib/spack/llnl/util/tty/__init__.py @@ -250,7 +250,7 @@ def ioctl_GWINSZ(fd): try: rc = struct.unpack('hh', fcntl.ioctl( fd, termios.TIOCGWINSZ, '1234')) - except: + except BaseException: return return rc rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) @@ -259,7 +259,7 @@ def ioctl_GWINSZ(fd): fd = os.open(os.ctermid(), os.O_RDONLY) rc = ioctl_GWINSZ(fd) os.close(fd) - except: + except BaseException: pass if not rc: rc = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80)) diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py index b04775b4f1..c70d796955 100644 --- a/lib/spack/llnl/util/tty/colify.py +++ b/lib/spack/llnl/util/tty/colify.py @@ -167,7 +167,7 @@ def colify(elts, **options): r, c = env_size.split('x') console_rows, console_cols = int(r), int(c) tty = True - except: + except BaseException: pass # Use only one column if not a tty. diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py index 02084cc382..e8f3ce4d57 100644 --- a/lib/spack/llnl/util/tty/log.py +++ b/lib/spack/llnl/util/tty/log.py @@ -166,7 +166,7 @@ def _file_descriptors_work(*streams): for stream in streams: stream.fileno() return True - except: + except BaseException: return False @@ -310,7 +310,7 @@ def __enter__(self): # need to pass this b/c multiprocessing closes stdin in child. try: input_stream = os.fdopen(os.dup(sys.stdin.fileno())) - except: + except BaseException: input_stream = None # just don't forward input if this fails self.process = multiprocessing.Process( @@ -483,7 +483,7 @@ def _writer_daemon(self, stdin): force_echo = True if xoff in controls: force_echo = False - except: + except BaseException: tty.error("Exception occurred in writer daemon!") traceback.print_exc() diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index cc03374769..aac1d38f5a 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -567,7 +567,7 @@ def child_process(child_pipe, input_stream): tty.msg(e.message) child_pipe.send(None) - except: + except BaseException: # catch ANYTHING that goes wrong in the child process exc_type, exc, tb = sys.exc_info() diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index d38f11f63b..d0c6c37e29 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -34,7 +34,7 @@ from llnl.util.filesystem import mkdirp from spack.repository import Repo from spack.spec import Spec -from spack.util.executable import which +from spack.util.executable import which, ProcessError from spack.util.naming import mod_to_class from spack.util.naming import simplify_name, valid_fully_qualified_module_name from spack.url import UndetectableNameError, UndetectableVersionError @@ -471,14 +471,14 @@ def __call__(self, stage, url): try: unzip = which('unzip') output = unzip('-lq', stage.archive_file, output=str) - except: + except ProcessError: output = '' else: try: tar = which('tar') output = tar('--exclude=*/*/*', '-tf', stage.archive_file, output=str) - except: + except ProcessError: output = '' lines = output.split('\n') diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index d4a59c9e8f..7c014e0a92 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -286,7 +286,7 @@ def wrapper(self, *args, ** kwargs): message='Unexpected exception thrown during install', text=text ) - except: + except BaseException: # Anything else is also an error duration = time.time() - start_time test_case.set_duration(duration) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index 46e8a5ae2e..91142579d5 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -491,7 +491,7 @@ def _read_suppress_error(): self._check_ref_counts() - except: + except BaseException: # If anything explodes, restore old data, skip write. self._data = old_data raise @@ -544,7 +544,7 @@ 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: + except BaseException: # 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 4ab76c8d2a..9aa6b9afd1 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -970,7 +970,7 @@ def from_list_url(pkg): except KeyError: tty.msg("Can not find version %s in url_list" % pkg.version) - except: + except BaseException: tty.msg("Could not determine url from list_url.") diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 775873df23..646969859a 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -410,8 +410,8 @@ def __call__(self, *argv, **kwargs): except SystemExit as e: self.returncode = e.code - except: - self.error = sys.exc_info()[1] + except BaseException as e: + self.error = e if fail_on_error: raise diff --git a/lib/spack/spack/test/llnl/util/lock.py b/lib/spack/spack/test/llnl/util/lock.py index 4466d5999b..4d74d68d73 100644 --- a/lib/spack/spack/test/llnl/util/lock.py +++ b/lib/spack/spack/test/llnl/util/lock.py @@ -98,7 +98,7 @@ comm = MPI.COMM_WORLD if comm.size > 1: mpi = True -except: +except ImportError: pass @@ -234,7 +234,7 @@ def wait(self): if include: try: functions[subcomm.rank](subcomm_barrier()) - except: + except BaseException: # aborting is the best we can do for MPI tests without # hanging, since we're using MPI barriers. This will fail # early and it loses the nice pytest output, but at least it diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py index a726023d95..6a1db6d221 100644 --- a/lib/spack/spack/util/module_cmd.py +++ b/lib/spack/spack/util/module_cmd.py @@ -82,13 +82,13 @@ def get_module_cmd_from_bash(bashopts=''): try: find_exec = re.search(r'.*`(.*(:? bash | sh ).*)`.*', module_func) exec_line = find_exec.group(1) - except: + except BaseException: try: # This will fail with nested parentheses. TODO: expand regex. find_exec = re.search(r'.*\(([^()]*(:? bash | sh )[^()]*)\).*', module_func) exec_line = find_exec.group(1) - except: + except BaseException: raise ModuleError('get_module_cmd cannot ' 'determine the module command from bash') diff --git a/var/spack/repos/builtin/packages/charm/package.py b/var/spack/repos/builtin/packages/charm/package.py index 944b46889f..7358b5588e 100644 --- a/var/spack/repos/builtin/packages/charm/package.py +++ b/var/spack/repos/builtin/packages/charm/package.py @@ -177,6 +177,6 @@ def install(self, spec, prefix): shutil.copy2(filepath, tmppath) os.remove(filepath) os.rename(tmppath, filepath) - except: + except (IOError, OSError): pass shutil.rmtree(join_path(prefix, "tmp")) diff --git a/var/spack/repos/builtin/packages/hdf5-blosc/package.py b/var/spack/repos/builtin/packages/hdf5-blosc/package.py index a12fb14d6d..9a472db102 100644 --- a/var/spack/repos/builtin/packages/hdf5-blosc/package.py +++ b/var/spack/repos/builtin/packages/hdf5-blosc/package.py @@ -184,7 +184,7 @@ def check_install(self, spec): try: check = Executable("./check") output = check(output=str) - except: + except ProcessError: output = "" success = output == expected if not success: diff --git a/var/spack/repos/builtin/packages/hdf5/package.py b/var/spack/repos/builtin/packages/hdf5/package.py index d499898a9d..fea0006d09 100644 --- a/var/spack/repos/builtin/packages/hdf5/package.py +++ b/var/spack/repos/builtin/packages/hdf5/package.py @@ -270,7 +270,7 @@ def check_install(self): try: check = Executable('./check') output = check(output=str) - except: + except ProcessError: output = "" success = output == expected if not success: diff --git a/var/spack/repos/builtin/packages/plasma/package.py b/var/spack/repos/builtin/packages/plasma/package.py index ffe0254651..0e8f7918f0 100644 --- a/var/spack/repos/builtin/packages/plasma/package.py +++ b/var/spack/repos/builtin/packages/plasma/package.py @@ -63,7 +63,7 @@ def edit(self, spec, prefix): for dep in ("blas", "lapack"): try: # in case the dependency does not provide header flags header_flags += " " + spec[dep].headers.cpp_flags - except: + except AttributeError: pass make_inc.filter("CFLAGS +[+]=", "CFLAGS += " + header_flags + " ") diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py index 15f2974328..b176169236 100644 --- a/var/spack/repos/builtin/packages/python/package.py +++ b/var/spack/repos/builtin/packages/python/package.py @@ -285,7 +285,7 @@ def _save_distutil_vars(self, prefix): Python._DISTUTIL_CACHE_FILENAME) with open(output_filename, 'w') as output_file: sjson.dump(self._distutil_vars, output_file) - except: + except Exception: tty.warn("Failed to save metadata for distutils. This might " "cause the extensions that are installed with " "distutils to call compilers directly avoiding " @@ -308,7 +308,7 @@ def _load_distutil_vars(self): if os.path.isfile(input_filename): with open(input_filename) as input_file: self._distutil_vars = sjson.load(input_file) - except: + except Exception: pass if not self._distutil_vars: