From 03b2eec74c703e2f4f6e10d3967326b86948c1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 3 Aug 2023 12:39:46 +0200 Subject: [PATCH] introduce "throw_if_false" function --- sphinxcontrib/phpdomain.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sphinxcontrib/phpdomain.py b/sphinxcontrib/phpdomain.py index aec0f19..7cea994 100644 --- a/sphinxcontrib/phpdomain.py +++ b/sphinxcontrib/phpdomain.py @@ -37,6 +37,15 @@ def log_warning(fromdocnode, message: str): logger.warning(f"[phpdomain] {message}", location=fromdocnode, type="phpdomain") +def throw_if_false(fromdocnode, value, message: str): + """ + Log warning if the value is not true and throw ValueError. Should set exit code to non-zero. + """ + if not value: + log_warning(fromdocnode, message) + raise ValueError + + php_sig_re = re.compile( r""" ^ @@ -205,8 +214,7 @@ def handle_signature(self, sig, signode): """ m = php_sig_re.match(sig) if m is None: - log_warning(signode, "Invalid signature: " + sig) - raise ValueError + throw_if_false(signode, False, "Invalid signature") visibility, modifiers, name_prefix, name, arglist, retann, enumtype = m.groups()