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

getdozer / dozer / 5709656380

pending completion
5709656380

push

github

web-flow
Version bump (#1808)

45512 of 59772 relevant lines covered (76.14%)

39312.43 hits per line

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

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

5
use actix_web::http::header::ContentType;
6
use actix_web::http::StatusCode;
7
use actix_web::HttpResponse;
8
use dozer_cache::dozer_log::errors::ReaderError;
9
use dozer_types::errors::types::{CannotConvertF64ToJson, TypeError};
10
use dozer_types::labels::Labels;
11
use dozer_types::thiserror::Error;
12
use dozer_types::{serde_json, thiserror};
13

14
use dozer_cache::errors::CacheError;
15
use handlebars::{RenderError, TemplateError};
16
use prost_reflect::{DescriptorError, Kind};
17

18
#[derive(Debug, Error)]
×
19
pub enum ApiInitError {
×
20
    #[error("Grpc error: {0}")]
21
    Grpc(#[from] GrpcError),
22
    #[error("Generation error: {0}")]
23
    Generation(#[from] GenerationError),
24
    #[error("Failed to create log reader builder: {0}")]
25
    CreateLogReaderBuilder(#[from] ReaderError),
26
    #[error("Failed to open or create cache: {0}")]
27
    OpenOrCreateCache(#[source] CacheError),
28
    #[error("Failed to find cache: {0}")]
29
    CacheNotFound(Labels),
30
    #[error("Failed to bind to address {0}: {1}")]
31
    FailedToBindToAddress(String, #[source] std::io::Error),
32
}
33

34
#[derive(Error, Debug)]
2✔
35
pub enum ApiError {
36
    #[error("Authentication error: {0}")]
37
    ApiAuthError(#[from] AuthError),
38
    #[error("Get by primary key is not supported when there is no primary key")]
39
    NoPrimaryKey,
40
    #[error("Get by primary key is not supported when it is composite: {0:?}")]
41
    MultiIndexFetch(String),
42
    #[error("Document not found")]
43
    NotFound(#[source] CacheError),
44
    #[error("Failed to count records")]
45
    CountFailed(#[source] CacheError),
46
    #[error("Failed to query cache: {0}")]
47
    QueryFailed(#[source] CacheError),
48
    #[error("Failed to get cache phase: {0}")]
49
    GetPhaseFailed(#[source] CacheError),
50
    #[error("Invalid primary key: {0}")]
51
    InvalidPrimaryKey(#[source] TypeError),
52
    #[error("Invalid access filter: {0}")]
53
    InvalidAccessFilter(#[source] serde_json::Error),
54
    #[error(transparent)]
×
55
    CannotConvertF64ToJson(#[from] CannotConvertF64ToJson),
×
56
}
×
57

×
58
#[derive(Error, Debug)]
×
59
pub enum GrpcError {
×
60
    #[error("Server reflection error: {0}")]
×
61
    ServerReflectionError(#[from] tonic_reflection::server::Error),
×
62
    #[error("Addr parse error: {0}: {1}")]
×
63
    AddrParse(String, #[source] AddrParseError),
×
64
    #[error("Transport error: {0:?}")]
65
    Transport(#[from] tonic::transport::Error),
66
}
×
67

68
impl From<ApiError> for tonic::Status {
69
    fn from(input: ApiError) -> Self {
×
70
        tonic::Status::new(tonic::Code::Unknown, input.to_string())
×
71
    }
×
72
}
73

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

108
#[derive(Error, Debug)]
×
109
pub enum AuthError {
110
    #[error("Cannot access this route.")]
111
    Unauthorized,
112
    #[error("JWT error: {0}")]
113
    JWT(#[from] jsonwebtoken::errors::Error),
114
}
115

116
impl actix_web::error::ResponseError for ApiError {
117
    fn error_response(&self) -> HttpResponse {
1✔
118
        HttpResponse::build(self.status_code())
1✔
119
            .insert_header(ContentType::json())
1✔
120
            .body(self.to_string())
1✔
121
    }
1✔
122

123
    fn status_code(&self) -> StatusCode {
1✔
124
        match *self {
1✔
125
            ApiError::InvalidPrimaryKey(_) | ApiError::InvalidAccessFilter(_) => {
126
                StatusCode::BAD_REQUEST
1✔
127
            }
128
            ApiError::ApiAuthError(_) => StatusCode::UNAUTHORIZED,
×
129
            ApiError::NotFound(_) => StatusCode::NOT_FOUND,
×
130
            ApiError::NoPrimaryKey | ApiError::MultiIndexFetch(_) => {
131
                StatusCode::UNPROCESSABLE_ENTITY
×
132
            }
133
            ApiError::QueryFailed(_)
134
            | ApiError::CountFailed(_)
135
            | ApiError::GetPhaseFailed(_)
136
            | ApiError::CannotConvertF64ToJson(_) => StatusCode::INTERNAL_SERVER_ERROR,
×
137
        }
138
    }
1✔
139
}
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