Skip to main content

rustfs_targets/
error.rs

1// Copyright 2024 RustFS Team
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
15use std::io;
16use thiserror::Error;
17
18/// Error types for the store
19#[derive(Debug, Error)]
20pub enum StoreError {
21    #[error("I/O error: {0}")]
22    Io(#[from] io::Error),
23
24    #[error("Serialization error: {0}")]
25    Serialization(String),
26
27    #[error("Deserialization error: {0}")]
28    Deserialization(String),
29
30    #[error("Compression error: {0}")]
31    Compression(String),
32
33    #[error("Entry limit exceeded")]
34    LimitExceeded,
35
36    #[error("Entry not found")]
37    NotFound,
38
39    #[error("Invalid entry: {0}")]
40    Internal(String), // Added internal error type
41}
42
43/// Error types for targets
44#[derive(Debug, Error)]
45pub enum TargetError {
46    #[error("Storage error: {0}")]
47    Storage(String),
48
49    #[error("Network error: {0}")]
50    Network(String),
51
52    #[error("Request error: {0}")]
53    Request(String),
54
55    #[error("JetStream publish error ({}): {detail}", if *.retryable { "retryable" } else { "terminal" })]
56    JetStreamPublish { retryable: bool, detail: String },
57
58    #[error("Timeout error: {0}")]
59    Timeout(String),
60
61    #[error("Authentication error: {0}")]
62    Authentication(String),
63
64    #[error("Configuration error: {0}")]
65    Configuration(String),
66
67    #[error("Encoding error: {0}")]
68    Encoding(String),
69
70    #[error("Serialization error: {0}")]
71    Serialization(String),
72
73    #[error("Target not connected")]
74    NotConnected,
75
76    #[error("Target initialization failed: {0}")]
77    Initialization(String),
78
79    #[error("Invalid ARN: {0}")]
80    InvalidARN(String),
81
82    #[error("Unknown error: {0}")]
83    Unknown(String),
84
85    #[error("Target is disabled")]
86    Disabled,
87
88    #[error("Queued payload dropped: {0}")]
89    Dropped(String),
90
91    #[error("Configuration parsing error: {0}")]
92    ParseError(String),
93
94    #[error("Failed to save configuration: {0}")]
95    SaveConfig(String),
96
97    #[error("Server not initialized: {0}")]
98    ServerNotInitialized(String),
99}
100
101impl From<url::ParseError> for TargetError {
102    fn from(err: url::ParseError) -> Self {
103        TargetError::Configuration(format!("URL parse error: {err}"))
104    }
105}