Skip to main content

raps_admin/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2025 Dmytro Yemelianov
3
4//! Error types for bulk admin operations
5
6use uuid::Uuid;
7
8/// Errors from bulk operations
9#[derive(Debug, thiserror::Error)]
10pub enum AdminError {
11    #[error("User not found in account: {email}")]
12    UserNotFound { email: String },
13
14    #[error("Invalid filter expression: {message}")]
15    InvalidFilter { message: String },
16
17    #[error("Operation not found: {id}")]
18    OperationNotFound { id: Uuid },
19
20    #[error("Operation cannot be resumed (status: {status})")]
21    CannotResume { status: String },
22
23    #[error("Invalid operation: {message}")]
24    InvalidOperation { message: String },
25
26    #[error("Rate limit exceeded, retry after {retry_after} seconds")]
27    RateLimited { retry_after: u64 },
28
29    #[error("API error: {status} - {message}")]
30    ApiError { status: u16, message: String },
31
32    #[error("State persistence error: {0}")]
33    StateError(#[from] std::io::Error),
34
35    #[error("Serialization error: {0}")]
36    SerializationError(#[from] serde_json::Error),
37
38    #[error(transparent)]
39    Other(#[from] anyhow::Error),
40}
41
42/// Standard exit codes for bulk operations
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub enum ExitCode {
45    /// All items processed successfully
46    Success = 0,
47    /// Some items failed
48    PartialSuccess = 1,
49    /// Operation could not start
50    Failure = 2,
51    /// User cancelled
52    Cancelled = 3,
53}
54
55impl From<ExitCode> for i32 {
56    fn from(code: ExitCode) -> Self {
57        code as i32
58    }
59}