{"record":{"id":"8f274b34a1da8d24","repo":"yewstack/yew","slug":"expected-block-or-if-after-else","errorCode":null,"errorMessage":"expected block or `if` after `else`","messagePattern":"expected block or `if` after `else`","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_if.rs","lineNumber":51,"sourceCode":"                    \"missing condition for `if` expression\",\n                ));\n            }\n            _ => {}\n        }\n        if input.is_empty() {\n            return Err(syn::Error::new(\n                cond.span(),\n                \"this `if` expression has a condition, but no block\",\n            ));\n        }\n\n        let then_branch = input.parse()?;\n        let else_branch = input\n            .parse::<Token![else]>()\n            .ok()\n            .map(|else_token| {\n                if input.is_empty() {\n                    return Err(syn::Error::new(\n                        else_token.span(),\n                        \"expected block or `if` after `else`\",\n                    ));\n                }\n\n                input.parse().map(|branch| (else_token, branch))\n            })\n            .transpose()?;\n\n        Ok(HtmlIf {\n            if_token,\n            cond,\n            then_branch,\n            else_branch,\n        })\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_if.rs#L33-L69","documentation":"When an `else` token follows the then-block, `HtmlIf::parse` requires more input after it; if the stream is empty immediately after `else`, this error is raised on the else token's span (html_if.rs:46-52). An `else` in `html!` must be followed by a brace block or another `if` expression, mirroring plain Rust.","triggerScenarios":"`html! { if cond { <a/> } else }` — a dangling `else` at the end of the macro input.","commonSituations":"Starting to add a fallback branch and not finishing it, a placeholder `else` left behind by a snippet, or refactoring branches and leaving the tail orphaned.","solutions":["Complete the branch: `else { <Fallback /> }`","Chain conditions with `else if` when the fallback is itself conditional","Delete the dangling `else` if no fallback is needed"],"exampleFix":"// before\nhtml! { if cond { <a/> } else }\n\n// after\nhtml! { if cond { <a/> } else { <b/> } }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `else` as incomplete until followed by `{` or `if`","Write both branches of an if/else in one editing pass","Delete unused fallback branches completely rather than leaving a dangling `else`"],"tags":["rust","yew","html-macro","if-expression","else","syntax"],"backgroundTag":"incomplete-if-expression","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}