splinter 0.3.14

Splinter is a privacy-focused platform for distributed applications that provides a blockchain-inspired networking environment for communication and transactions between organizations.
Documentation
// Copyright 2018-2020 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::error::Error;
use std::fmt;

use crate::node_registry::InvalidNodeError;

#[derive(Debug)]
pub enum YamlNodeRegistryError {
    PoisonLockError(String),
    SerdeError(serde_yaml::Error),
    IoError(std::io::Error),
    InvalidNode(InvalidNodeError),
}

impl Error for YamlNodeRegistryError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        match self {
            YamlNodeRegistryError::PoisonLockError(_) => None,
            YamlNodeRegistryError::SerdeError(err) => Some(err),
            YamlNodeRegistryError::IoError(err) => Some(err),
            YamlNodeRegistryError::InvalidNode(err) => Some(err),
        }
    }
}

impl fmt::Display for YamlNodeRegistryError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            YamlNodeRegistryError::PoisonLockError(e) => write!(f, "Error locking file: {}", e),
            YamlNodeRegistryError::SerdeError(e) => write!(f, "Serde error: {}", e),
            YamlNodeRegistryError::IoError(e) => write!(f, "IO error: {}", e),
            YamlNodeRegistryError::InvalidNode(e) => write!(f, "invalid node in YAML file: {}", e),
        }
    }
}

impl From<std::io::Error> for YamlNodeRegistryError {
    fn from(err: std::io::Error) -> YamlNodeRegistryError {
        YamlNodeRegistryError::IoError(err)
    }
}

impl From<serde_yaml::Error> for YamlNodeRegistryError {
    fn from(err: serde_yaml::Error) -> YamlNodeRegistryError {
        YamlNodeRegistryError::SerdeError(err)
    }
}

impl From<InvalidNodeError> for YamlNodeRegistryError {
    fn from(err: InvalidNodeError) -> Self {
        YamlNodeRegistryError::InvalidNode(err)
    }
}