gateway_mm/src/error.rs

56 lines
1.6 KiB
Rust

// Copyright (C) 2022 Maxime “pep” Buquet <pep@bouah.net>
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
// for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
//
use std::convert::From;
use std::error::Error as StdError;
#[derive(Debug)]
pub enum Error {
Zbus(zbus::Error),
ZbusFdo(zbus::fdo::Error),
}
impl StdError for Error {
fn cause(&self) -> Option<&dyn StdError> {
match self {
Error::Zbus(e) => Some(e),
Error::ZbusFdo(e) => Some(e),
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::Zbus(e) => write!(fmt, "zbus error: {}", e),
Error::ZbusFdo(e) => write!(fmt, "zbus fdo error: {}", e),
}
}
}
impl From<zbus::Error> for Error {
fn from(err: zbus::Error) -> Error {
Error::Zbus(err)
}
}
impl From<zbus::fdo::Error> for Error {
fn from(err: zbus::fdo::Error) -> Error {
Error::ZbusFdo(err)
}
}