From be694ed7d842c4536843bff4cda5e9ea6bce31bf Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Mon, 4 Nov 2024 15:03:39 +0100 Subject: [PATCH] project: Fix raise-without-from-inside-except (B904) Derived from flake8-bugbear, see https://docs.astral.sh/ruff/rules/raise-without-from-inside-except/ Signed-off-by: Pieter De Gendt --- src/west/app/config.py | 4 ++-- src/west/configuration.py | 4 ++-- src/west/manifest.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/west/app/config.py b/src/west/app/config.py index 63454bab..cfb5236b 100644 --- a/src/west/app/config.py +++ b/src/west/app/config.py @@ -169,11 +169,11 @@ def delete(self, args): try: self.config.delete(args.name, configfile=configfile) return - except KeyError: + except KeyError as err: if i == len(configfiles) - 1: self.dbg( f'{args.name} was not set in requested location(s)') - raise CommandError(returncode=1) + raise CommandError(returncode=1) from err except PermissionError as pe: self._perm_error(pe, configfile, args.name) diff --git a/src/west/configuration.py b/src/west/configuration.py index d5b18f3f..426c9b1c 100644 --- a/src/west/configuration.py +++ b/src/west/configuration.py @@ -99,8 +99,8 @@ def _get(self, option, getter): try: return getter(section, key) - except (configparser.NoOptionError, configparser.NoSectionError): - raise KeyError(option) + except (configparser.NoOptionError, configparser.NoSectionError) as err: + raise KeyError(option) from err def set(self, option: str, value: Any): section, key = _InternalCF.parse_key(option) diff --git a/src/west/manifest.py b/src/west/manifest.py index 04810666..da557d35 100644 --- a/src/west/manifest.py +++ b/src/west/manifest.py @@ -1920,12 +1920,12 @@ def get_option(option, default=None): current_abspath = topdir_abspath / current_relpath try: current_data = current_abspath.read_text(encoding=Manifest.encoding) - except FileNotFoundError: + except FileNotFoundError as err: raise MalformedConfig( f'file not found: manifest file {current_abspath} ' '(from configuration options ' f'manifest.path="{manifest_path_option}", ' - f'manifest.file="{manifest_file}")') + f'manifest.file="{manifest_file}")') from err current_repo_abspath = topdir_abspath / manifest_path