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 b002ba8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 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
2 changes: 1 addition & 1 deletion test/log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b002ba8

Please sign in to comment.