podman-container-tools/podman · error · ValueError
Invalid inline if/else syntax: {inner}
Error message
Invalid inline if/else syntax: {inner} What it means
Wrapped error from the inline-conditional path in render(): a token containing both ' if ' and ' else ' (e.g. '<< "foo" if cond else "bar" >>') failed during split or evaluation. The original exception is chained (__cause__), and in practice the cause is almost always 'undefined variable' — truthy(cond) only understands a bare defined variable name (currently only is_quadlet), not expressions like 'a == b', 'a and b', or multi-word conditions.
Source
Thrown at hack/markdown-preprocess:109
continue
if inner == "endif":
if not stack:
raise ValueError("`end` without `if`")
stack.pop()
continue
# inline "X if cond else Y" ---
if " if " in inner and " else " in inner:
try:
# split by " if " then " else "
then_part, rest = inner.split(" if ", 1)
cond, else_part = rest.split(" else ", 1)
cond = cond.strip()
chosen = then_part if truthy(cond) else else_part
if is_active():
out.append(chosen.strip().strip("'\""))
except Exception as e:
raise ValueError(f"Invalid inline if/else syntax: {inner}") from e
continue
# Unrecognized token (e.g. `<<a|b>>` for replace_type, or `<<subcommand>>`):
# preserve verbatim so downstream processing can handle it.
if is_active():
out.append(m.group(0))
# trailing literal
if is_active():
out.append(text[pos:])
if stack:
raise ValueError("unclosed `if` block(s)")
return "".join(out)
def process(self, infile:str):
"""
Main calling point: preprocesses one fileView on GitHub (pinned to a2409076ef)
Solutions
- Use a defined variable as the condition: '<< "foo" if is_quadlet else "bar" >>'
- For multi-word or negated conditions use the block form: << if not is_quadlet >>...<< endif >>
- If the text is literal prose containing 'if'/'else', move it out of the <<...>> token or rephrase so the token does not contain both ' if ' and ' else '
- Inspect ex.__cause__ of the wrapping error to see the underlying failure
Example fix
# before << "--pod" if pod option else "--container" >> # after << "--pod" if is_quadlet else "--container" >>
Defensive patterns
Strategy: validation
Validate before calling
import re, pathlib, sys
ALLOWED = {'is_quadlet'}
pat = re.compile(r'<<(.*?)>>', re.DOTALL)
bad = []
for p in pathlib.Path('docs/source/markdown/options').glob('*.md'):
for m in pat.finditer(p.read_text()):
inner = m.group(1).strip()
if ' if ' in inner and ' else ' in inner:
try:
_, rest = inner.split(' if ', 1)
cond = rest.split(' else ', 1)[0].strip()
var = cond[4:].strip() if cond.startswith('not ') else cond
if var not in ALLOWED:
bad.append(f'{p}: inline cond {cond!r} is not a defined variable')
except ValueError:
bad.append(f'{p}: unparseable inline conditional {inner!r}')
if bad:
sys.exit('\n'.join(bad)) Try / catch
try:
rendered = pre.render(text, {'is_quadlet': is_quadlet})
except ValueError as e:
cause = e.__cause__ # underlying failure, e.g. undefined variable
raise SystemExit(f'{path}: {e} (cause: {cause})') from None Prevention
- Inline conditionals accept only a bare defined variable between ' if ' and ' else ' — no comparisons, no multi-word phrases
- Keep prose about shell if/else keywords OUT of <<...>> tokens; the parser treats any token containing both ' if ' and ' else ' as a conditional
- Prefer the block form for anything non-trivial; it yields clearer errors
When it happens
Trigger: A token like '<< "ps" if is quadlet else "podman" >>' (multi-word cond), '<< X if a == b else Y >>', or any cond that is not exactly 'is_quadlet'/'not is_quadlet'. Also triggered by prose inside <<...>> that incidentally contains the words ' if ' and ' else ' (e.g. explaining shell syntax), which the parser then misreads as an inline conditional.
Common situations: Writing man-page prose about shell if/else keywords inside double-angle tokens; trying boolean expressions the mini-template does not support; using an undefined variable name in the short form.
Related errors
- undefined variable: {name}
- `else` without `if`
- multiple `else` in the same `if`
- `end` without `if`
- unclosed `if` block(s)
AI-assisted analysis of podman-container-tools/podman@a2409076ef (2026-08-15).
Data as JSON: /api/errors/fd7b40e02c9c5e46.
Report an issue: GitHub.