|
|
@ -1,8 +1,7 @@ |
|
|
|
use oxrdf::TermParseError; |
|
|
|
use oxrdf::TermParseError; |
|
|
|
use std::error::Error; |
|
|
|
use std::io; |
|
|
|
use std::ops::Range; |
|
|
|
use std::ops::Range; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::sync::Arc; |
|
|
|
use std::{fmt, io}; |
|
|
|
|
|
|
|
use thiserror::Error; |
|
|
|
use thiserror::Error; |
|
|
|
|
|
|
|
|
|
|
|
/// Error returned during SPARQL result formats format parsing.
|
|
|
|
/// Error returned during SPARQL result formats format parsing.
|
|
|
@ -42,28 +41,26 @@ impl From<quick_xml::Error> for ParseError { |
|
|
|
quick_xml::Error::Io(error) => { |
|
|
|
quick_xml::Error::Io(error) => { |
|
|
|
Self::Io(Arc::try_unwrap(error).unwrap_or_else(|e| io::Error::new(e.kind(), e))) |
|
|
|
Self::Io(Arc::try_unwrap(error).unwrap_or_else(|e| io::Error::new(e.kind(), e))) |
|
|
|
} |
|
|
|
} |
|
|
|
_ => Self::Syntax(SyntaxError { |
|
|
|
_ => Self::Syntax(SyntaxError::Xml(error)), |
|
|
|
inner: SyntaxErrorKind::Xml(error), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// An error in the syntax of the parsed file.
|
|
|
|
/// An error in the syntax of the parsed file.
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug, Error)] |
|
|
|
pub struct SyntaxError { |
|
|
|
pub enum SyntaxError { |
|
|
|
pub(crate) inner: SyntaxErrorKind, |
|
|
|
#[error(transparent)] |
|
|
|
} |
|
|
|
Json(#[from] json_event_parser::SyntaxError), |
|
|
|
|
|
|
|
#[error(transparent)] |
|
|
|
#[derive(Debug)] |
|
|
|
Xml(#[from] quick_xml::Error), |
|
|
|
pub(crate) enum SyntaxErrorKind { |
|
|
|
#[error("Error {error} on '{term}' in line {}", location.start.line + 1)] |
|
|
|
Json(json_event_parser::SyntaxError), |
|
|
|
|
|
|
|
Xml(quick_xml::Error), |
|
|
|
|
|
|
|
Term { |
|
|
|
Term { |
|
|
|
|
|
|
|
#[source] |
|
|
|
error: TermParseError, |
|
|
|
error: TermParseError, |
|
|
|
term: String, |
|
|
|
term: String, |
|
|
|
location: Range<TextPosition>, |
|
|
|
location: Range<TextPosition>, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
#[error("{msg}")] |
|
|
|
Msg { |
|
|
|
Msg { |
|
|
|
msg: String, |
|
|
|
msg: String, |
|
|
|
location: Option<Range<TextPosition>>, |
|
|
|
location: Option<Range<TextPosition>>, |
|
|
@ -74,30 +71,26 @@ impl SyntaxError { |
|
|
|
/// Builds an error from a printable error message.
|
|
|
|
/// Builds an error from a printable error message.
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub(crate) fn msg(msg: impl Into<String>) -> Self { |
|
|
|
pub(crate) fn msg(msg: impl Into<String>) -> Self { |
|
|
|
Self { |
|
|
|
Self::Msg { |
|
|
|
inner: SyntaxErrorKind::Msg { |
|
|
|
|
|
|
|
msg: msg.into(), |
|
|
|
msg: msg.into(), |
|
|
|
location: None, |
|
|
|
location: None, |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Builds an error from a printable error message and a location
|
|
|
|
/// Builds an error from a printable error message and a location
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub(crate) fn located_message(msg: impl Into<String>, location: Range<TextPosition>) -> Self { |
|
|
|
pub(crate) fn located_message(msg: impl Into<String>, location: Range<TextPosition>) -> Self { |
|
|
|
Self { |
|
|
|
Self::Msg { |
|
|
|
inner: SyntaxErrorKind::Msg { |
|
|
|
|
|
|
|
msg: msg.into(), |
|
|
|
msg: msg.into(), |
|
|
|
location: Some(location), |
|
|
|
location: Some(location), |
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// The location of the error inside of the file.
|
|
|
|
/// The location of the error inside of the file.
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub fn location(&self) -> Option<Range<TextPosition>> { |
|
|
|
pub fn location(&self) -> Option<Range<TextPosition>> { |
|
|
|
match &self.inner { |
|
|
|
match self { |
|
|
|
SyntaxErrorKind::Json(e) => { |
|
|
|
Self::Json(e) => { |
|
|
|
let location = e.location(); |
|
|
|
let location = e.location(); |
|
|
|
Some( |
|
|
|
Some( |
|
|
|
TextPosition { |
|
|
|
TextPosition { |
|
|
@ -111,37 +104,9 @@ impl SyntaxError { |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
SyntaxErrorKind::Term { location, .. } => Some(location.clone()), |
|
|
|
Self::Term { location, .. } => Some(location.clone()), |
|
|
|
SyntaxErrorKind::Msg { location, .. } => location.clone(), |
|
|
|
Self::Msg { location, .. } => location.clone(), |
|
|
|
SyntaxErrorKind::Xml(_) => None, |
|
|
|
Self::Xml(_) => None, |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for SyntaxError { |
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
|
|
|
|
|
|
|
match &self.inner { |
|
|
|
|
|
|
|
SyntaxErrorKind::Json(e) => e.fmt(f), |
|
|
|
|
|
|
|
SyntaxErrorKind::Xml(e) => e.fmt(f), |
|
|
|
|
|
|
|
SyntaxErrorKind::Term { |
|
|
|
|
|
|
|
error, |
|
|
|
|
|
|
|
term, |
|
|
|
|
|
|
|
location, |
|
|
|
|
|
|
|
} => write!(f, "{error} on '{term}' in line {}", location.start.line + 1), |
|
|
|
|
|
|
|
SyntaxErrorKind::Msg { msg, .. } => f.write_str(msg), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Error for SyntaxError { |
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
fn source(&self) -> Option<&(dyn Error + 'static)> { |
|
|
|
|
|
|
|
match &self.inner { |
|
|
|
|
|
|
|
SyntaxErrorKind::Json(e) => Some(e), |
|
|
|
|
|
|
|
SyntaxErrorKind::Xml(e) => Some(e), |
|
|
|
|
|
|
|
SyntaxErrorKind::Term { error, .. } => Some(error), |
|
|
|
|
|
|
|
SyntaxErrorKind::Msg { .. } => None, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -149,9 +114,9 @@ impl Error for SyntaxError { |
|
|
|
impl From<SyntaxError> for io::Error { |
|
|
|
impl From<SyntaxError> for io::Error { |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
fn from(error: SyntaxError) -> Self { |
|
|
|
fn from(error: SyntaxError) -> Self { |
|
|
|
match error.inner { |
|
|
|
match error { |
|
|
|
SyntaxErrorKind::Json(error) => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
SyntaxError::Json(error) => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
SyntaxErrorKind::Xml(error) => match error { |
|
|
|
SyntaxError::Xml(error) => match error { |
|
|
|
quick_xml::Error::Io(error) => { |
|
|
|
quick_xml::Error::Io(error) => { |
|
|
|
Arc::try_unwrap(error).unwrap_or_else(|e| Self::new(e.kind(), e)) |
|
|
|
Arc::try_unwrap(error).unwrap_or_else(|e| Self::new(e.kind(), e)) |
|
|
|
} |
|
|
|
} |
|
|
@ -160,16 +125,8 @@ impl From<SyntaxError> for io::Error { |
|
|
|
} |
|
|
|
} |
|
|
|
_ => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
_ => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
}, |
|
|
|
}, |
|
|
|
SyntaxErrorKind::Term { .. } => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
SyntaxError::Term { .. } => Self::new(io::ErrorKind::InvalidData, error), |
|
|
|
SyntaxErrorKind::Msg { msg, .. } => Self::new(io::ErrorKind::InvalidData, msg), |
|
|
|
SyntaxError::Msg { msg, .. } => Self::new(io::ErrorKind::InvalidData, msg), |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<json_event_parser::SyntaxError> for SyntaxError { |
|
|
|
|
|
|
|
fn from(error: json_event_parser::SyntaxError) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
inner: SyntaxErrorKind::Json(error), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|