uri_register/
error.rs

1// Copyright TELICENT LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Error types for the URI register service
16
17use std::fmt;
18
19/// Result type alias for URI register operations
20pub type Result<T> = std::result::Result<T, Error>;
21
22/// Configuration error types with specific variants
23#[derive(Debug, Clone, thiserror::Error)]
24pub enum ConfigurationError {
25    /// Cache size is invalid (must be greater than 0)
26    #[error("cache_size must be greater than 0, got {0}")]
27    InvalidCacheSize(usize),
28
29    /// Max connections is invalid (must be greater than 0)
30    #[error("max_connections must be greater than 0, got {0}")]
31    InvalidMaxConnections(u32),
32
33    /// Table name is invalid (must be a valid SQL identifier)
34    #[error("table_name is invalid: {0}")]
35    InvalidTableName(String),
36
37    /// Backoff configuration is invalid
38    #[error("backoff configuration is invalid: {0}")]
39    InvalidBackoff(String),
40}
41
42/// Error types for URI register operations
43#[derive(Debug, thiserror::Error)]
44pub enum Error {
45    /// Database operation failed (error message is sanitized to remove passwords)
46    #[error("Database error: {0}")]
47    Database(String),
48
49    /// Database connection pool error
50    #[error("Connection pool error: {0}")]
51    ConnectionPool(String),
52
53    /// Cache operation failed
54    #[error("Cache error: {0}")]
55    Cache(String),
56
57    /// Invalid configuration
58    #[error("Configuration error: {0}")]
59    Configuration(#[from] ConfigurationError),
60
61    /// URI validation failed
62    #[error("Invalid URI: {0}")]
63    InvalidUri(String),
64}
65
66impl Error {
67    /// Create a connection pool error
68    pub fn connection_pool(msg: impl fmt::Display) -> Self {
69        Self::ConnectionPool(msg.to_string())
70    }
71
72    /// Create a cache error
73    pub fn cache(msg: impl fmt::Display) -> Self {
74        Self::Cache(msg.to_string())
75    }
76
77    /// Create an invalid URI error
78    pub fn invalid_uri(msg: impl fmt::Display) -> Self {
79        Self::InvalidUri(msg.to_string())
80    }
81}