fix: legible error on missing template placeholder (v0.2.1)
next() on a template source did template.format(...) directly, so a placeholder not supplied in next(**fields) leaked a bare KeyError. catch KeyError/IndexError and raise a clear ValueError naming the missing placeholder. verified: next() without a required field -> ValueError naming it; happy path intact. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
parent
ca708191c8
commit
aa661bd6de
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "aioproxies"
|
name = "aioproxies"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
description = "proxy parsing, formatting, health, and pool management for aiohttp/aioweb, camoufox, and socks5"
|
description = "proxy parsing, formatting, health, and pool management for aiohttp/aioweb, camoufox, and socks5"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|||||||
@ -18,4 +18,4 @@ __all__ = [
|
|||||||
"to_proxy",
|
"to_proxy",
|
||||||
]
|
]
|
||||||
|
|
||||||
__version__ = "0.2.0"
|
__version__ = "0.2.1"
|
||||||
|
|||||||
@ -123,7 +123,15 @@ class AioProxies:
|
|||||||
if self._static is not None:
|
if self._static is not None:
|
||||||
return self._static
|
return self._static
|
||||||
if self.template is not None:
|
if self.template is not None:
|
||||||
return parse(self.template.format(session=self.session_id(), **fields))
|
try:
|
||||||
|
filled = self.template.format(session=self.session_id(), **fields)
|
||||||
|
except (KeyError, IndexError) as exc:
|
||||||
|
# a template placeholder wasn't supplied in next(**fields) — fail loud
|
||||||
|
# but legible instead of leaking a bare KeyError from str.format
|
||||||
|
raise ValueError(
|
||||||
|
f"template placeholder {exc} not provided; pass it to next(**fields)"
|
||||||
|
) from exc
|
||||||
|
return parse(filled)
|
||||||
return self._next_from_list()
|
return self._next_from_list()
|
||||||
|
|
||||||
def _next_from_list(self) -> Proxy:
|
def _next_from_list(self) -> Proxy:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user