llm_cost_ops/domain/
error.rs1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, CostOpsError>;
4
5#[derive(Error, Debug)]
6pub enum CostOpsError {
7 #[error("Database error: {0}")]
8 Database(#[from] sqlx::Error),
9
10 #[error("IO error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("Serialization error: {0}")]
14 Serialization(#[from] serde_json::Error),
15
16 #[error("TOML deserialization error: {0}")]
17 TomlDe(#[from] toml::de::Error),
18
19 #[error("Configuration error: {0}")]
20 Config(String),
21
22 #[error("Validation error: {0}")]
23 Validation(String),
24
25 #[error("Invalid token count: {0}")]
26 InvalidTokenCount(String),
27
28 #[error("Token count mismatch: calculated={calculated}, reported={reported}")]
29 TokenCountMismatch {
30 calculated: u64,
31 reported: u64,
32 },
33
34 #[error("Missing organization ID")]
35 MissingOrganizationId,
36
37 #[error("Future timestamp not allowed")]
38 FutureTimestamp,
39
40 #[error("Provider not found: {0}")]
41 ProviderNotFound(String),
42
43 #[error("Pricing model not found for provider={provider}, model={model}, date={date}")]
44 PricingModelNotFound {
45 provider: String,
46 model: String,
47 date: String,
48 },
49
50 #[error("Invalid pricing structure: {0}")]
51 InvalidPricingStructure(String),
52
53 #[error("Currency conversion error: {0}")]
54 CurrencyConversion(String),
55
56 #[error("Integration error: {0}")]
57 Integration(String),
58
59 #[error("Authorization error: {0}")]
60 Authorization(String),
61
62 #[error("Internal error: {0}")]
63 Internal(String),
64}
65
66impl CostOpsError {
67 pub fn config<S: Into<String>>(msg: S) -> Self {
68 CostOpsError::Config(msg.into())
69 }
70
71 pub fn validation<S: Into<String>>(msg: S) -> Self {
72 CostOpsError::Validation(msg.into())
73 }
74
75 pub fn internal<S: Into<String>>(msg: S) -> Self {
76 CostOpsError::Internal(msg.into())
77 }
78}