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

UnexpectedEofInStartPhase

UnexpectedEofInStartPhase

Error message

Unexpected end of file in start phase

What it means

XML parser error in Phase::Start: an EOF token was encountered before the document element started (only whitespace, comments, PI, doctype and one root element are allowed in the start phase). Recorded on parser.errors and the document is finalized.

Source

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

                }
                Token::Cdata { .. } => {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::UnexpectedTokenInStartPhase,
                    ));

                    self.append_cdata_to_doc(token_and_info)?;
                }
                Token::Character { value, .. } => {
                    if !is_whitespace(*value) {
                        self.errors.push(Error::new(
                            token_and_info.span,
                            ErrorKind::UnexpectedCharacter,
                        ));
                    }
                }
                Token::Eof => {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::UnexpectedEofInStartPhase,
                    ));

                    self.process_token(token_and_info, Some(Phase::EndPhase))?;
                }
                Token::Doctype { .. } => {
                    let document_type = self.create_document_type_for_token(token_and_info);

                    self.append_node(self.document.as_ref().unwrap(), document_type);
                }
                _ => {
                    self.errors.push(Error::new(
                        token_and_info.span,
                        ErrorKind::UnexpectedTokenInStartPhase,
                    ));
                }
            },

View on GitHub (pinned to 5176682b65)

Solutions

  1. Provide a non-empty XML document with a root element
  2. Check that the input was not truncated before the root element
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_xml_parser/src/parser/mod.rs:288 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/01cd0b258618715e. Report an issue: GitHub.