use std::error::Error;
use std::fmt;
use std::io;
use std::str;
pub type PointCloudResult<T> = Result<T,PointCloudError>;
#[derive(Debug)]
pub enum PointCloudError {
DataAccessError {
index: usize,
slice_name: String,
},
NameNotInTree(String),
IoError(io::Error),
ParsingError(ParsingError),
NodeNestingError {
message: &'static str,
},
}
impl fmt::Display for PointCloudError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&PointCloudError::IoError(ref e) => write!(f,"{}",e),
&PointCloudError::ParsingError(ref e) => write!(f,"{}",e),
&PointCloudError::DataAccessError { .. } => {
write!(f,"there was an issue grabbing a data point or label")
}
&PointCloudError::NameNotInTree { .. } => {
write!(f,"there was an issue grabbing a name from the known names")
}
&PointCloudError::NodeNestingError { .. } => {
write!(f,"There is a temporary node in a working tree")
}
}
}
}
#[allow(deprecated)]
impl Error for PointCloudError {
fn description(&self) -> &str {
match self {
&PointCloudError::IoError(ref e) => e.description(),
&PointCloudError::ParsingError(ref e) => e.description(),
&PointCloudError::DataAccessError { .. } => {
"there was an issue grabbing a data point or label"
}
&PointCloudError::NameNotInTree { .. } => {
"there was an issue grabbing a name from the known names"
}
&PointCloudError::NodeNestingError { .. } => {
"There is a temporary node in a working tree"
}
}
}
fn cause(&self) -> Option<&dyn Error> {
match self {
&PointCloudError::IoError(ref e) => Some(e),
&PointCloudError::ParsingError(ref e) => Some(e),
&PointCloudError::DataAccessError { .. } => None,
&PointCloudError::NameNotInTree { .. } => None,
&PointCloudError::NodeNestingError { .. } => None,
}
}
}
impl From<io::Error> for PointCloudError {
fn from(err: io::Error) -> Self {
PointCloudError::IoError(err)
}
}
impl From<PointCloudError> for io::Error {
fn from(err: PointCloudError) -> Self {
match err {
PointCloudError::IoError(e) => e,
e => io::Error::new(io::ErrorKind::Other, Box::new(e)),
}
}
}
impl PointCloudError {
pub fn node_nesting(message: &'static str) -> PointCloudError {
PointCloudError::NodeNestingError { message }
}
pub fn data_access(index: usize, slice_name: String) -> PointCloudError {
PointCloudError::DataAccessError { index, slice_name }
}
}
#[derive(Debug)]
pub enum ParsingError {
MalformedYamlError {
file_name: String,
field: String,
},
MissingYamlError {
file_name: String,
field: String,
},
CSVReadError {
file_name: String,
line_number: usize,
key: String,
},
RegularParsingError(&'static str),
}
impl fmt::Display for ParsingError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}
impl Error for ParsingError {
fn description(&self) -> &str {
match self {
&ParsingError::MalformedYamlError { .. } => "there is a error reading a yaml entry",
&ParsingError::MissingYamlError { .. } => "not all message fields set",
&ParsingError::CSVReadError { .. } => "issue reading a CSV entry",
&ParsingError::RegularParsingError(..) => "Error parsing a string",
}
}
fn cause(&self) -> Option<&dyn Error> {
match self {
&ParsingError::MalformedYamlError { .. } => None,
&ParsingError::MissingYamlError { .. } => None,
&ParsingError::CSVReadError { .. } => None,
&ParsingError::RegularParsingError(..) => None,
}
}
}