• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4382580286

pending completion
4382580286

push

github

GitHub
feat: Separate cache operation log environment and index environments (#1199)

1370 of 1370 new or added lines in 33 files covered. (100.0%)

28671 of 41023 relevant lines covered (69.89%)

51121.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/dozer-api/src/errors.rs
1
#![allow(clippy::enum_variant_names)]
2
use std::path::PathBuf;
3

4
use actix_web::http::header::ContentType;
5
use actix_web::http::StatusCode;
6
use actix_web::HttpResponse;
7
use dozer_types::thiserror::Error;
8
use dozer_types::{serde_json, thiserror};
9

10
use dozer_cache::errors::CacheError;
11
use dozer_types::errors::internal::BoxedError;
12
use dozer_types::errors::types::TypeError;
13
use handlebars::{RenderError, TemplateError};
14
use prost_reflect::{DescriptorError, Kind};
15

16
#[derive(Error, Debug)]
×
17
pub enum ApiError {
18
    #[error("Authentication error: {0}")]
19
    ApiAuthError(#[from] AuthError),
20
    #[error("Failed to open cache: {0}")]
21
    OpenCache(#[source] CacheError),
22
    #[error("Failed to open cache: {0}")]
23
    CacheNotFound(String),
24
    #[error("Get by primary key is not supported when there is no primary key")]
25
    NoPrimaryKey,
26
    #[error("Get by primary key is not supported when it is composite: {0:?}")]
27
    MultiIndexFetch(String),
28
    #[error("Document not found")]
29
    NotFound(#[source] CacheError),
30
    #[error("Failed to count records")]
31
    CountFailed(#[source] CacheError),
32
    #[error("Failed to query cache")]
33
    QueryFailed(#[source] CacheError),
34
    #[error("Internal error: {0}")]
35
    InternalError(#[from] BoxedError),
36
    #[error("Type error: {0}")]
37
    TypeError(#[from] TypeError),
38
    #[error("Failed to bind to address {0}: {1}")]
39
    FailedToBindToAddress(String, #[source] std::io::Error),
40
}
41

42
impl ApiError {
43
    pub fn map_serialization_error(e: serde_json::Error) -> ApiError {
×
44
        ApiError::TypeError(TypeError::SerializationError(
×
45
            dozer_types::errors::types::SerializationError::Json(e),
×
46
        ))
×
47
    }
×
48
    pub fn map_deserialization_error(e: serde_json::Error) -> ApiError {
×
49
        ApiError::TypeError(TypeError::DeserializationError(
×
50
            dozer_types::errors::types::DeserializationError::Json(e),
×
51
        ))
×
52
    }
×
53
}
×
54

×
55
#[derive(Error, Debug)]
×
56
pub enum GrpcError {
57
    #[error("Internal gRPC server error: {0}")]
×
58
    InternalError(#[from] BoxedError),
59
    #[error("Cannot send to broadcast channel")]
60
    CannotSendToBroadcastChannel,
61
    #[error("Generation error: {0}")]
62
    GenerationError(#[from] GenerationError),
63
    #[error("Schema not found: {0}")]
64
    SchemaNotFound(#[from] CacheError),
65
    #[error("Server reflection error: {0}")]
66
    ServerReflectionError(#[from] tonic_reflection::server::Error),
67
    #[error("Transport error: {0}")]
68
    Transport(#[from] tonic::transport::Error),
69
}
70
impl From<GrpcError> for tonic::Status {
71
    fn from(input: GrpcError) -> Self {
×
72
        tonic::Status::new(tonic::Code::Internal, input.to_string())
×
73
    }
×
74
}
×
75

×
76
impl From<ApiError> for tonic::Status {
77
    fn from(input: ApiError) -> Self {
×
78
        tonic::Status::new(tonic::Code::Unknown, input.to_string())
×
79
    }
×
80
}
×
81

×
82
#[derive(Error, Debug)]
×
83
pub enum GenerationError {
84
    // clippy says `TemplateError` is 136 bytes on stack and much larger than other variants, so we box it.
×
85
    #[error("Handlebars template error: {0}")]
86
    HandlebarsTemplate(#[source] Box<TemplateError>),
87
    #[error("Handlebars render error: {0}")]
88
    HandlebarsRender(#[from] RenderError),
89
    #[error("Failed to write to file {0:?}: {1}")]
90
    FailedToWriteToFile(PathBuf, #[source] std::io::Error),
91
    #[error("directory path {0:?} does not exist")]
92
    DirPathNotExist(PathBuf),
93
    #[error("DozerType to Proto type not supported: {0}")]
94
    DozerToProtoTypeNotSupported(String),
95
    #[error("Failed to create proto descriptor: {0}")]
96
    FailedToCreateProtoDescriptor(#[source] std::io::Error),
97
    #[error("Failed to read proto descriptor: {0}")]
98
    FailedToReadProtoDescriptor(#[source] std::io::Error),
99
    #[error("Failed to decode proto descriptor: {0}")]
100
    FailedToDecodeProtoDescriptor(#[source] DescriptorError),
101
    #[error("Service not found: {0}")]
102
    ServiceNotFound(String),
103
    #[error("Field not found: {field_name} in message: {message_name}")]
104
    FieldNotFound {
105
        message_name: String,
106
        field_name: String,
107
    },
108
    #[error("Expected message field: {filed_name}, but found: {actual:?}")]
109
    ExpectedMessageField { filed_name: String, actual: Kind },
110
    #[error("Unexpected method {0}")]
111
    UnexpectedMethod(String),
112
    #[error("Missing count method for: {0}")]
113
    MissingCountMethod(String),
114
    #[error("Missing query method for: {0}")]
115
    MissingQueryMethod(String),
116
}
117

118
#[derive(Error, Debug)]
×
119
pub enum AuthError {
120
    #[error("Cannot access this route.")]
×
121
    Unauthorized,
122
    #[error("Invalid token provided")]
123
    InvalidToken,
124
    #[error("Issuer is invalid")]
125
    InvalidIssuer,
126
    #[error("Internal error: {0}")]
127
    InternalError(#[from] BoxedError),
128
}
129

130
impl actix_web::error::ResponseError for ApiError {
131
    fn error_response(&self) -> HttpResponse {
×
132
        HttpResponse::build(self.status_code())
×
133
            .insert_header(ContentType::json())
×
134
            .body(self.to_string())
×
135
    }
×
136

×
137
    fn status_code(&self) -> StatusCode {
×
138
        match *self {
×
139
            ApiError::TypeError(_) => StatusCode::BAD_REQUEST,
×
140
            ApiError::ApiAuthError(_) => StatusCode::UNAUTHORIZED,
×
141
            ApiError::NotFound(_) => StatusCode::NOT_FOUND,
×
142
            ApiError::NoPrimaryKey | ApiError::MultiIndexFetch(_) => {
×
143
                StatusCode::UNPROCESSABLE_ENTITY
×
144
            }
145
            ApiError::InternalError(_)
×
146
            | ApiError::OpenCache(_)
147
            | ApiError::CacheNotFound(_)
148
            | ApiError::QueryFailed(_)
149
            | ApiError::CountFailed(_)
150
            | ApiError::FailedToBindToAddress(_, _) => StatusCode::INTERNAL_SERVER_ERROR,
×
151
        }
152
    }
×
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc