Skip to content

Commit

Permalink
introduce "throw_if_false" function
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 3, 2023
1 parent b828e7a commit 03b2eec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sphinxcontrib/phpdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
^
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 03b2eec

Please sign in to comment.