From b002ba89a0154bab17bc5c269540ec6bb39ce441 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 ++++++++++-- test/log.txt | 2 +- 2 files changed, 11 insertions(+), 3 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() diff --git a/test/log.txt b/test/log.txt index f218c03..f058e6a 100644 --- a/test/log.txt +++ b/test/log.txt @@ -1,5 +1,5 @@ test/log.md:3: WARNING: Unknown directive type: 'php:namespacee' [myst.directive_unknown] -test/log.md:8: WARNING: [phpdomain] Invalid signature: x(); +test/log.md:8: WARNING: [phpdomain] Invalid signature test/log.md:13: [phpdomain] Target Aa::simplify not found test/log.md:15: [phpdomain] Target A::simplifyy not found test/ns.md:48: [phpdomain] Target A2::simplify not found