{"record":{"id":"12ad420779dbf2b3","repo":"swc-project/swc","slug":"unexpected-end-of-file","errorCode":null,"errorMessage":"Unexpected end of file","messagePattern":"Unexpected end of file","errorType":"validation","errorClass":"swc_css_parser::error::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/input.rs","lineNumber":359,"sourceCode":"                res\n            }\n            None => return None,\n            _ => {\n                unreachable!(\"Not allowed in the list of component values\")\n            }\n        }\n    }\n\n    fn cur(&mut self) -> PResult<Cow<'_, TokenAndSpan>> {\n        match self.input {\n            InputType::Tokens(input) => {\n                let idx = match self.idx.last() {\n                    Some(idx) => idx,\n                    _ => {\n                        let bp = input.span.hi;\n                        let span = Span::new(bp, bp);\n\n                        return Err(Error::new(span, ErrorKind::Eof));\n                    }\n                };\n\n                let token_and_span = match input.tokens.get(*idx) {\n                    Some(token_and_span) => token_and_span,\n                    None => {\n                        let bp = input.span.hi;\n                        let span = Span::new(bp, bp);\n\n                        return Err(Error::new(span, ErrorKind::Eof));\n                    }\n                };\n\n                Ok(Cow::Borrowed(token_and_span))\n            }\n            InputType::ListOfComponentValues(input) => {\n                let token_and_span = match self.get_component_value(&input.children, 0) {\n                    Some(token_or_block) => match token_or_block {","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/input.rs#L341-L377","documentation":"Input::cur() was called on the token-stream input when the parser has already consumed every token: the position stack ('idx') is empty, so there is no current token to return. The parser surfaces this as an unexpected-EOF error positioned at the end of input. It almost always means the grammar expected more input (a closing brace, paren, or value) but the stylesheet ended.","triggerScenarios":"Unclosed '{' (rule block), '(' (media query or declaration value), unclosed string/comment, or a truncated file: '.a { color: red;' or '@media (width { ... }' reaching end of input while the parser still asks for the next token.","commonSituations":"Incremental/streaming pipelines that feed partial buffers to the parser; files truncated by a failed write or an interrupted network transfer; user-authored CSS in CMS fields where the closing brace was never typed; code that re-parses fragments without balancing delimiters first.","solutions":["Balance delimiters: every '{', '(', '[' closed, strings and comments terminated","If parsing a fragment, wrap or repair it (append the missing closers) before parsing","For streams, buffer until the stylesheet is complete instead of parsing partial input","Locate the innermost unclosed construct by counting delimiters from the start of input"],"exampleFix":"/* before */\n.a { color: red;\n/* after */\n.a { color: red; }","handlingStrategy":"validation","validationCode":"// Reject obviously unbalanced/truncated stylesheets before parsing\nfunction isBalanced(css) {\n  const pairs = { '{': '}', '(': ')', '[': ']' };\n  const stack = [];\n  for (const ch of css.replace(/\\./g, '').replace(/\"[^\"]*\"|'[^']*'|\\/\\*[\\s\\S]*?\\*\\//g, '')) {\n    if (pairs[ch]) stack.push(ch);\n    else if (Object.values(pairs).includes(ch)) { if (pairs[stack.pop()] !== ch) return false; }\n  }\n  return stack.length === 0;\n}","typeGuard":null,"tryCatchPattern":"// JS\ntry { parse(css, opts); } catch (e) { if (/end of file/.test(e.message)) requestMoreInputOrAppendClosers(css); }","preventionTips":["Never parse partial buffers — buffer streams until EOF","Auto-append missing closers for CMS/user input before parsing","Treat Eof-kind errors as 'incomplete input', distinct from syntax errors"],"tags":["css","parser","eof","truncated-input"],"backgroundTag":"unexpected-eof-parse-error","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"}