diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-07-20 06:54:22 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-07-20 05:32:28 -0700 |
commit | 5313297fe84c596f9222a4890dd45a53a6d4d632 (patch) | |
tree | ceacf73477e129786a8566fff146c18cd57c0edf /coverage/tomlconfig.py | |
parent | de38a0e74a8683a3d3381038aeee4d226cc5b714 (diff) | |
download | python-coveragepy-git-5313297fe84c596f9222a4890dd45a53a6d4d632.tar.gz |
fix: raise chained errors with "from" #998
This makes exceptions report their causes correctly, as "The above exception was
the direct cause of the following exception" instead of "During handling of the
above exception, another exception occurred."
Diffstat (limited to 'coverage/tomlconfig.py')
-rw-r--r-- | coverage/tomlconfig.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py index aa11a8a9..8212cfe6 100644 --- a/coverage/tomlconfig.py +++ b/coverage/tomlconfig.py @@ -49,7 +49,7 @@ class TomlConfigParser: try: self.data = tomli.loads(toml_text) except tomli.TOMLDecodeError as err: - raise TomlDecodeError(str(err)) + raise TomlDecodeError(str(err)) from err return [filename] else: has_toml = re.search(r"^\[tool\.coverage\.", toml_text, flags=re.MULTILINE) @@ -95,8 +95,8 @@ class TomlConfigParser: raise configparser.NoSectionError(section) try: return name, data[option] - except KeyError: - raise configparser.NoOptionError(option, name) + except KeyError as exc: + raise configparser.NoOptionError(option, name) from exc def has_option(self, section, option): _, data = self._get_section(section) @@ -149,7 +149,7 @@ class TomlConfigParser: except re.error as e: raise CoverageException( f"Invalid [{name}].{option} value {value!r}: {e}" - ) + ) from e return values def getint(self, section, option): |