{"record":{"id":"fd7b40e02c9c5e46","repo":"podman-container-tools/podman","slug":"invalid-inline-if-else-syntax-inner","errorCode":null,"errorMessage":"Invalid inline if/else syntax: {inner}","messagePattern":"Invalid inline if/else syntax: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hack/markdown-preprocess","lineNumber":109,"sourceCode":"                continue\n            if inner == \"endif\":\n                if not stack:\n                    raise ValueError(\"`end` without `if`\")\n                stack.pop()\n                continue\n\n            # inline \"X if cond else Y\" ---\n            if \" if \" in inner and \" else \" in inner:\n                try:\n                    # split by \" if \" then \" else \"\n                    then_part, rest = inner.split(\" if \", 1)\n                    cond, else_part = rest.split(\" else \", 1)\n                    cond = cond.strip()\n                    chosen = then_part if truthy(cond) else else_part\n                    if is_active():\n                        out.append(chosen.strip().strip(\"'\\\"\"))\n                except Exception as e:\n                    raise ValueError(f\"Invalid inline if/else syntax: {inner}\") from e\n                continue\n\n            # Unrecognized token (e.g. `<<a|b>>` for replace_type, or `<<subcommand>>`):\n            # preserve verbatim so downstream processing can handle it.\n            if is_active():\n                out.append(m.group(0))\n\n        # trailing literal\n        if is_active():\n            out.append(text[pos:])\n\n        if stack:\n            raise ValueError(\"unclosed `if` block(s)\")\n        return \"\".join(out)\n\n    def process(self, infile:str):\n        \"\"\"\n        Main calling point: preprocesses one file","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/podman-container-tools/podman/blob/a2409076ef2fef60ad9ac046375dedc7d9410ef4/hack/markdown-preprocess#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n<< \"--pod\" if pod option else \"--container\" >>\n\n# after\n<< \"--pod\" if is_quadlet else \"--container\" >>","handlingStrategy":"validation","validationCode":"import re, pathlib, sys\nALLOWED = {'is_quadlet'}\npat = re.compile(r'<<(.*?)>>', re.DOTALL)\nbad = []\nfor p in pathlib.Path('docs/source/markdown/options').glob('*.md'):\n    for m in pat.finditer(p.read_text()):\n        inner = m.group(1).strip()\n        if ' if ' in inner and ' else ' in inner:\n            try:\n                _, rest = inner.split(' if ', 1)\n                cond = rest.split(' else ', 1)[0].strip()\n                var = cond[4:].strip() if cond.startswith('not ') else cond\n                if var not in ALLOWED:\n                    bad.append(f'{p}: inline cond {cond!r} is not a defined variable')\n            except ValueError:\n                bad.append(f'{p}: unparseable inline conditional {inner!r}')\nif bad:\n    sys.exit('\\n'.join(bad))","typeGuard":null,"tryCatchPattern":"try:\n    rendered = pre.render(text, {'is_quadlet': is_quadlet})\nexcept ValueError as e:\n    cause = e.__cause__  # underlying failure, e.g. undefined variable\n    raise SystemExit(f'{path}: {e} (cause: {cause})') from None","preventionTips":["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"],"tags":["markdown","docs","preprocessor","inline-conditional"],"backgroundTag":null,"analyzedSha":"a2409076ef2fef60ad9ac046375dedc7d9410ef4","analyzedAt":"2026-08-15T15:57:05.625Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}