diem_config/config/
error.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use thiserror::Error;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error("Invariant violation: {0}")]
13    InvariantViolation(String),
14    #[error("Error accessing {0}: {1}")]
15    IO(String, #[source] std::io::Error),
16    #[error("Error (de)serializing {0}: {1}")]
17    BCS(&'static str, #[source] bcs::Error),
18    #[error("Error (de)serializing {0}: {1}")]
19    Yaml(String, #[source] yaml_serde::Error),
20    #[error("Config is missing expected value: {0}")]
21    Missing(&'static str),
22}
23
24pub fn invariant(cond: bool, msg: String) -> Result<(), Error> {
25    if !cond {
26        Err(Error::InvariantViolation(msg))
27    } else {
28        Ok(())
29    }
30}