error.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // -*- coding: utf-8 -*-
  2. //
  3. // Copyright (C) 2024 Michael Büsch <m@bues.ch>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. //
  18. // SPDX-License-Identifier: GPL-2.0-or-later
  19. use anyhow as ah;
  20. #[derive(Debug)]
  21. pub enum Error {
  22. Ah(ah::Error),
  23. Sql(rusqlite::Error),
  24. }
  25. impl std::error::Error for Error {}
  26. impl std::fmt::Display for Error {
  27. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  28. match self {
  29. Self::Ah(e) => write!(f, "{e}"),
  30. Self::Sql(e) => write!(f, "{e}"),
  31. }
  32. }
  33. }
  34. impl From<rusqlite::Error> for Error {
  35. fn from(e: rusqlite::Error) -> Self {
  36. Self::Sql(e)
  37. }
  38. }
  39. impl From<ah::Error> for Error {
  40. fn from(e: ah::Error) -> Self {
  41. Self::Ah(e)
  42. }
  43. }
  44. // vim: ts=4 sw=4 expandtab