{"record":{"id":"9d331ba3cf8e532a","repo":"swc-project/swc","slug":"internal-error-entered-unreachable-code-9d331b","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_css_compat/src/compiler/custom_media.rs","lineNumber":321,"sourceCode":"                                            ),\n                                        }));\n                                }\n                            }\n                            MediaConditionType::WithoutOr(media_condition) => {\n                                let mut media_condition = self\n                                    .media_condition_without_or_to_media_condition(media_condition);\n\n                                if new_media_condition.conditions.is_empty() {\n                                    let media_in_parens = if matches!(\n                                        media_condition.conditions.first(),\n                                        Some(MediaConditionAllType::MediaInParens(_))\n                                    ) {\n                                        match media_condition.conditions.pop() {\n                                            Some(MediaConditionAllType::MediaInParens(inner)) => {\n                                                inner\n                                            }\n                                            _ => {\n                                                unreachable!();\n                                            }\n                                        }\n                                    } else {\n                                        MediaInParens::MediaCondition(media_condition)\n                                    };\n\n                                    new_media_condition.conditions.push(\n                                        MediaConditionAllType::MediaInParens(media_in_parens),\n                                    );\n                                } else {\n                                    new_media_condition\n                                        .conditions\n                                        .push(MediaConditionAllType::Or(MediaOr {\n                                            span: DUMMY_SP,\n                                            keyword: None,\n                                            condition: MediaInParens::MediaCondition(\n                                                media_condition,\n                                            ),","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_compat/src/compiler/custom_media.rs#L303-L339","documentation":"The @custom-media compat pass rewrites custom media queries. When a media condition 'without or' collapses to empty, it unwraps its single MediaInParens child and re-wraps it; the guard fires when the preceding is-match says the first element is a MediaInParens but popping yields something else — an internal invariant break in the transform rather than a user error.","triggerScenarios":"Running swc_css_compat's custom-media lowering (browser-compat presets) on stylesheets whose `@custom-media` definitions reduce to a single condition — e.g. `@custom-media --x (min-width: 600px)` used as `@media (--x)` — particularly with negations or nested condition combinations.","commonSituations":"Rust pipelines mimicking postcss-preset-env with @custom-media at-rules; design-token breakpoint systems defined via custom media; upgrades of swc_css_* changing which branch executes.","solutions":["Expand the custom media manually: replace `@custom-media --x (min-width: 600px)` + `@media (--x)` with `@media (min-width: 600px)` and rebuild","Disable the custom-media compat feature (raise the browser target) so the pass does not run","Update swc_css_compat to the latest release and, if reproducible, attach the failing query to a swc issue"],"exampleFix":"/* before */\n@custom-media --wide (min-width: 600px);\n@media (--wide) { .x { color: red } }\n\n/* after */\n@media (min-width: 600px) { .x { color: red } }","handlingStrategy":"fallback","validationCode":"// Detect @custom-media rules before running compat passes\nfn uses_custom_media(css: &str) -> bool {\n    css.contains(\"@custom-media\")\n}\n\nif uses_custom_media(&css) {\n    // expand or strip them before swc_css_compat\n}","typeGuard":null,"tryCatchPattern":"let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    compile_css(&css, compat_target)\n}));\nmatch out {\n    Ok(v) => v,\n    Err(p) if panic_message(&p).contains(\"unreachable\") => {\n        // fallback: retry with the custom-media compat feature disabled / target raised\n    }\n    Err(p) => std::panic::resume_unwind(p),\n}","preventionTips":["Prefer standard media queries over `@custom-media` when tooling maturity matters","Expand custom media definitions manually in critical build paths","Keep swc_css_compat current; custom-media handling has had multiple fixes","Run CSS compat in a subprocess during rollout of new swc versions"],"tags":["swc","css","custom-media","compat","media-query"],"backgroundTag":"custom-media-query-rewrite","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}