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

getdozer / dozer / 5881075993

16 Aug 2023 03:58PM UTC coverage: 77.415% (-0.2%) from 77.649%
5881075993

push

github

web-flow
feat: replace jaeger with xray (#1862)

feat: replace jaeger with xray

23 of 23 new or added lines in 2 files covered. (100.0%)

46085 of 59530 relevant lines covered (77.41%)

55729.22 hits per line

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

29.41
/dozer-api/src/errors.rs
1
#![allow(clippy::enum_variant_names)]
2
use std::net::{AddrParseError, SocketAddr};
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::ReaderBuilderError;
9
use dozer_types::errors::internal::BoxedError;
10
use dozer_types::errors::types::{CannotConvertF64ToJson, TypeError};
11
use dozer_types::labels::Labels;
12
use dozer_types::thiserror::Error;
13
use dozer_types::{serde_json, thiserror};
14

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

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

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

×
59
#[derive(Error, Debug)]
×
60
pub enum GrpcError {
61
    #[error("Server reflection error: {0}")]
62
    ServerReflectionError(#[from] tonic_reflection::server::Error),
63
    #[error("Addr parse error: {0}: {1}")]
64
    AddrParse(String, #[source] AddrParseError),
65
    #[error("Failed to listen to address {0}: {1:?}")]
66
    Listen(SocketAddr, #[source] BoxedError),
67
}
68

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

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

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

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

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