summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-08-15 17:44:56 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-08-15 18:24:30 +0200
commit78454983e0472a57db7e7949916269a29cd1f857 (patch)
tree96835c21d92e0a4d745bef0a881679415da30c7a
parent28f171d1bbf79e6bba05779daa13d5cbb8deed52 (diff)
downloadqutebrowser-78454983e0472a57db7e7949916269a29cd1f857.tar.gz
qutebrowser-78454983e0472a57db7e7949916269a29cd1f857.zip
config: Use a single argument for _handle_error()
Needed for the next commit. Done in both config.py and configfiles.py for consistency.
-rw-r--r--qutebrowser/config/config.py8
-rw-r--r--qutebrowser/config/configfiles.py18
2 files changed, 13 insertions, 13 deletions
diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py
index b2736158f..d29bfcb61 100644
--- a/qutebrowser/config/config.py
+++ b/qutebrowser/config/config.py
@@ -605,13 +605,13 @@ class ConfigContainer:
pattern=self._pattern)
@contextlib.contextmanager
- def _handle_error(self, action: str, name: str) -> Iterator[None]:
+ def _handle_error(self, action: str) -> Iterator[None]:
try:
yield
except configexc.Error as e:
if self._configapi is None:
raise
- text = "While {} '{}'".format(action, name)
+ text = f"While {action}"
self._configapi.errors.append(configexc.ConfigErrorDesc(text, e))
def _with_prefix(self, prefix: str) -> 'ConfigContainer':
@@ -639,7 +639,7 @@ class ConfigContainer:
if configdata.is_valid_prefix(name):
return self._with_prefix(name)
- with self._handle_error('getting', name):
+ with self._handle_error(f"getting '{name}'"):
if self._configapi is None:
# access from Python code
return self._config.get(name)
@@ -662,7 +662,7 @@ class ConfigContainer:
return
name = self._join(attr)
- with self._handle_error('setting', name):
+ with self._handle_error(f"setting '{name}'"):
self._config.set_obj(name, value, pattern=self._pattern)
def _join(self, attr: str) -> str:
diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py
index f2651d1cd..db9eda2f3 100644
--- a/qutebrowser/config/configfiles.py
+++ b/qutebrowser/config/configfiles.py
@@ -653,7 +653,7 @@ class ConfigAPI:
self._warn_autoconfig = warn_autoconfig
@contextlib.contextmanager
- def _handle_error(self, action: str, name: str) -> Iterator[None]:
+ def _handle_error(self, action: str) -> Iterator[None]:
"""Catch config-related exceptions and save them in self.errors."""
try:
yield
@@ -662,13 +662,13 @@ class ConfigAPI:
new_err = err.with_text(e.basename)
self.errors.append(new_err)
except configexc.Error as e:
- text = "While {} '{}'".format(action, name)
+ text = f"While {action}"
self.errors.append(configexc.ConfigErrorDesc(text, e))
except urlmatch.ParseError as e:
- text = "While {} '{}' and parsing pattern".format(action, name)
+ text = f"While {action} and parsing pattern"
self.errors.append(configexc.ConfigErrorDesc(text, e))
except keyutils.KeyParseError as e:
- text = "While {} '{}' and parsing key".format(action, name)
+ text = f"While {action} and parsing key"
self.errors.append(configexc.ConfigErrorDesc(text, e))
def finalize(self) -> None:
@@ -686,24 +686,24 @@ class ConfigAPI:
"""Load the autoconfig.yml file which is used for :set/:bind/etc."""
self._warn_autoconfig = False
if load_config:
- with self._handle_error('reading', 'autoconfig.yml'):
+ with self._handle_error("reading 'autoconfig.yml'"):
read_autoconfig()
def get(self, name: str, pattern: str = None) -> Any:
"""Get a setting value from the config, optionally with a pattern."""
- with self._handle_error('getting', name):
+ with self._handle_error(f"getting '{name}'"):
urlpattern = urlmatch.UrlPattern(pattern) if pattern else None
return self._config.get_mutable_obj(name, pattern=urlpattern)
def set(self, name: str, value: Any, pattern: str = None) -> None:
"""Set a setting value in the config, optionally with a pattern."""
- with self._handle_error('setting', name):
+ with self._handle_error(f"setting '{name}'"):
urlpattern = urlmatch.UrlPattern(pattern) if pattern else None
self._config.set_obj(name, value, pattern=urlpattern)
def bind(self, key: str, command: Optional[str], mode: str = 'normal') -> None:
"""Bind a key to a command, with an optional key mode."""
- with self._handle_error('binding', key):
+ with self._handle_error(f"binding '{key}'"):
seq = keyutils.KeySequence.parse(key)
if command is None:
raise configexc.Error("Can't bind {key} to None (maybe you "
@@ -713,7 +713,7 @@ class ConfigAPI:
def unbind(self, key: str, mode: str = 'normal') -> None:
"""Unbind a key from a command, with an optional key mode."""
- with self._handle_error('unbinding', key):
+ with self._handle_error(f"unbinding '{key}'"):
seq = keyutils.KeySequence.parse(key)
self._keyconfig.unbind(seq, mode=mode)