swc-project/swc · error · swc_xml_parser::error::Error

UnexpectedEofInMainPhase

UnexpectedEofInMainPhase

Error message

Unexpected end of file in main phase

What it means

Fired in the XML parser's main phase (process_token): the token stream ended (EOF) while the parser still expected markup — this signals truncated or unterminated XML input, e.g. a document ending inside an open element or before the required structure is complete. It is a sentinel guard against running out of tokens mid-parse.

Source

Thrown at crates/swc_xml_parser/src/parser/mod.rs:365

                    }
                }
                Token::Comment { .. } => {
                    let comment = self.create_comment(token_and_info);

                    self.append_node(self.get_current_element(), comment);
                }
                Token::ProcessingInstruction { .. } => {
                    let processing_instruction = self.create_processing_instruction(token_and_info);

                    self.append_node(self.get_current_element(), processing_instruction);
                }
                Token::Cdata { .. } => {
                    let cdata = self.create_cdata_section(token_and_info);

                    self.append_node(self.get_current_element(), cdata);
                }
                Token::Eof => {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::UnexpectedEofInMainPhase,
                    ));

                    self.process_token(token_and_info, Some(Phase::EndPhase))?;
                }
                _ => {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::UnexpectedTokenInMainPhase,
                    ));
                }
            },
            Phase::EndPhase => match &token_and_info.token {
                Token::Comment { .. } => {
                    self.append_comment_to_doc(token_and_info)?;
                }
                Token::ProcessingInstruction { .. } => {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close all open elements before end of input
  2. Verify the document was not truncated
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_xml_parser/src/parser/mod.rs:365 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/c2b1c4f795aad68a. Report an issue: GitHub.