swc-project/swc · error · swc_xml_parser::error::Error
UnexpectedTokenInEndPhase
UnexpectedTokenInEndPhase
Error message
Unexpected token in end phase
What it means
XML parser error in Phase::End (after the root element closed): a token other than the allowed trailing comments, processing instructions and whitespace (e.g. further elements or CDATA) was encountered. The error is recorded and the token is ignored while finishing the document.
Source
Thrown at crates/swc_xml_parser/src/parser/mod.rs:387
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 { .. } => {
self.append_processing_instruction_to_doc(token_and_info)?;
}
Token::Cdata { .. } => {
self.errors.push(Error::new(
token_and_info.span,
ErrorKind::UnexpectedTokenInEndPhase,
));
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.stopped = true;
}
_ => {View on GitHub (pinned to 5176682b65)
Solutions
- Remove any content after the root element's end tag except comments/PI/whitespace
- Move stray markup inside the root element
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_xml_parser/src/parser/mod.rs:387 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/18946eb0f08c172d.
Report an issue: GitHub.