common_runtime/
error.rs

1// Copyright 2023 Greptime 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::any::Any;
16
17use common_error::ext::ErrorExt;
18use common_macro::stack_trace_debug;
19use snafu::{Location, Snafu};
20use tokio::task::JoinError;
21
22pub type Result<T> = std::result::Result<T, Error>;
23
24#[derive(Snafu)]
25#[snafu(visibility(pub(crate)))]
26#[stack_trace_debug]
27pub enum Error {
28    #[snafu(display("Failed to build runtime"))]
29    BuildRuntime {
30        #[snafu(source)]
31        error: std::io::Error,
32        #[snafu(implicit)]
33        location: Location,
34    },
35
36    #[snafu(display("Failed to build runtime rate limiter"))]
37    BuildRuntimeRateLimiter {
38        #[snafu(implicit)]
39        location: Location,
40        #[snafu(source)]
41        error: ratelimit::Error,
42    },
43
44    #[snafu(display("Repeated task {} is already started", name))]
45    IllegalState {
46        name: String,
47        #[snafu(implicit)]
48        location: Location,
49    },
50
51    #[snafu(display("Failed to wait for repeated task {} to stop", name))]
52    WaitGcTaskStop {
53        name: String,
54        #[snafu(source)]
55        error: JoinError,
56        #[snafu(implicit)]
57        location: Location,
58    },
59}
60
61impl ErrorExt for Error {
62    fn as_any(&self) -> &dyn Any {
63        self
64    }
65}