// Copyright (C) 2022 Maxime “pep” Buquet // // 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 . // // use std::convert::From; use std::error::Error as StdError; use mmdbus::dbus; use xmpp_parsers::JidParseError; #[derive(Debug)] pub enum Error { DBusError(dbus::Error), InvalidArgs, JidParseError(JidParseError), } impl StdError for Error { fn cause(&self) -> Option<&dyn StdError> { match self { Error::DBusError(e) => Some(e), Error::InvalidArgs => None, Error::JidParseError(e) => Some(e), } } } impl std::fmt::Display for Error { fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { match self { Error::DBusError(e) => write!(fmt, "dbus error: {}", e), Error::InvalidArgs => write!(fmt, "invalid arguments"), Error::JidParseError(e) => write!(fmt, "jid parse error: {}", e), } } } impl From for Error { fn from(err: dbus::Error) -> Error { Error::DBusError(err) } } impl From for Error { fn from(err: JidParseError) -> Error { Error::JidParseError(err) } }