feat(html/parser): Add a method to get error message (#4623)

This commit is contained in:
Pig Fang 2022-05-12 11:45:56 +08:00 committed by GitHub
parent ede955391b
commit cac4f6e265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -30,7 +30,7 @@ impl Error {
}
}
pub fn message(&self) -> Cow<str> {
pub fn message(&self) -> Cow<'static, str> {
match &self.inner.1 {
ErrorKind::Eof => "Unexpected end of file".into(),
ErrorKind::Ignore => "Not an error".into(),

View File

@ -26,8 +26,8 @@ impl Error {
}
}
pub fn to_diagnostics<'a>(&self, handler: &'a Handler) -> DiagnosticBuilder<'a> {
let msg: Cow<_> = match &self.inner.1 {
pub fn message(&self) -> Cow<'static, str> {
match &self.inner.1 {
ErrorKind::Eof => "Unexpected end of file".into(),
ErrorKind::ControlCharacterInInputStream => "Control character in input stream".into(),
ErrorKind::NoncharacterInInputStream => "Noncharacter in input stream".into(),
@ -138,8 +138,11 @@ impl Error {
"Eof in element that can contain only text".into()
}
ErrorKind::UnexpectedToken => "Unexpected token".into(),
};
handler.struct_span_err(self.inner.0, &msg)
}
}
pub fn to_diagnostics<'a>(&self, handler: &'a Handler) -> DiagnosticBuilder<'a> {
handler.struct_span_err(self.inner.0, &self.message())
}
}