promad/
error.rs

1// ┌───────────────────────────────────────────────────────────────────────────┐
2// │                                                                           │
3// │  ██████╗ ██████╗  ██████╗   Copyright (C) The Prospective Company         │
4// │  ██╔══██╗██╔══██╗██╔═══██╗  All Rights Reserved - April 2022              │
5// │  ██████╔╝██████╔╝██║   ██║                                                │
6// │  ██╔═══╝ ██╔══██╗██║   ██║  Proprietary and confidential. Unauthorized    │
7// │  ██║     ██║  ██║╚██████╔╝  copying of this file, via any medium is       │
8// │  ╚═╝     ╚═╝  ╚═╝ ╚═════╝   strictly prohibited.                          │
9// │                                                                           │
10// └───────────────────────────────────────────────────────────────────────────┘
11
12use std::sync::{PoisonError, RwLockReadGuard, RwLockWriteGuard};
13
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16    #[error("Sqlx error: {0}")]
17    DatabaseError(#[from] sqlx::Error),
18    #[error("No such migration: {0}")]
19    NoSuchMigration(String),
20    #[error("{db_migration_count} migrations have been applied to the database, but {local_migration_count} migrations have been found locally")]
21    DeletedMigrations {
22        db_migration_count: usize,
23        local_migration_count: usize,
24    },
25    #[error("Duplicate migration name: {0}")]
26    DuplicateMigrationName(String),
27    #[error(
28        "The migration history shows that {remote_name} should be the next migration, but locally there is {local_name}"
29    )]
30    HistoryMigrationMismatch {
31        remote_name: String,
32        local_name: String,
33    },
34    #[error("Failed to acquire cache log")]
35    LockError(String),
36}
37
38impl<'a, T> From<PoisonError<RwLockReadGuard<'a, T>>> for Error {
39    fn from(e: PoisonError<RwLockReadGuard<'a, T>>) -> Self {
40        Error::LockError(e.to_string())
41    }
42}
43
44impl<'a, T> From<PoisonError<RwLockWriteGuard<'a, T>>> for Error {
45    fn from(e: PoisonError<RwLockWriteGuard<'a, T>>) -> Self {
46        Error::LockError(e.to_string())
47    }
48}
49
50pub type Result<A> = std::result::Result<A, Error>;