tibba_config/
lib.rs

1// Copyright 2025 Tree xie.
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.
14use snafu::Snafu;
15use tibba_error::Error as BaseError;
16
17mod app_config;
18
19// Error enum for handling various error types in the configuration
20#[derive(Debug, Snafu)]
21pub enum Error {
22    #[snafu(display("{category}, url parse error {source}"))]
23    Url {
24        category: String,
25        source: url::ParseError,
26    },
27    #[snafu(display("{category}, config error {source}"))]
28    Config {
29        category: String,
30        source: config::ConfigError,
31    },
32    #[snafu(display("{category}, parse duration error {source}"))]
33    ParseDuration {
34        category: String,
35        source: humantime::DurationError,
36    },
37}
38
39impl From<Error> for BaseError {
40    fn from(val: Error) -> Self {
41        let (category, err) = match val {
42            Error::Url { category, source } => (category, source.to_string()),
43            Error::Config { category, source } => (category, source.to_string()),
44            Error::ParseDuration { category, source } => (category, source.to_string()),
45        };
46
47        BaseError::new(err)
48            .with_sub_category(&category)
49            .with_category("config")
50            .with_exception(true)
51    }
52}
53
54pub use app_config::*;