Skip to main content

pop_fork/error/
cache.rs

1// SPDX-License-Identifier: GPL-3.0
2
3//! Cache-related error types.
4
5use std::error::Error as StdError;
6use thiserror::Error;
7
8/// Errors that can occur when interacting with the storage cache.
9#[derive(Debug, Error)]
10pub enum CacheError {
11	/// Database error.
12	#[error("Database error: {0}")]
13	Database(#[from] diesel::result::Error),
14	/// Database connection error.
15	#[error("Database connection error: {0}")]
16	Connection(#[from] diesel::result::ConnectionError),
17	/// Migration error.
18	#[error("Migration error: {0}")]
19	Migration(#[from] diesel_migrations::MigrationError),
20	/// Connection pool get error (wrapping bb8 RunError).
21	#[error("Connection pool get error: {0}")]
22	PoolGet(#[from] diesel_async::pooled_connection::bb8::RunError),
23	/// Connection pool build error.
24	#[error("Connection pool build error: {0}")]
25	PoolBuild(#[from] diesel_async::pooled_connection::PoolError),
26	/// IO error.
27	#[error("IO error: {0}")]
28	Io(#[from] std::io::Error),
29	/// Data corruption detected in the cache.
30	#[error("Data corruption: {0}")]
31	DataCorruption(String),
32	/// Duplicated keys used
33	#[error("Duplicated keys")]
34	DuplicatedKeys,
35}
36
37impl From<Box<dyn StdError + Send + Sync>> for CacheError {
38	fn from(e: Box<dyn StdError + Send + Sync>) -> Self {
39		// Migrations return boxed errors; fold them into a descriptive error variant
40		CacheError::DataCorruption(format!("{e}"))
41	}
42}