opentelemetry_gcloud_trace/
errors.rs1use gcloud_sdk::error::Error;
2use opentelemetry_sdk::ExportError;
3use rsb_derive::*;
4
5pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
6
7#[derive(Debug)]
8pub enum GcloudTraceError {
9 SystemError(GcloudTraceSystemError),
10 NetworkError(GcloudTraceNetworkError),
11}
12
13impl std::fmt::Display for GcloudTraceError {
14 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
15 match *self {
16 GcloudTraceError::SystemError(ref err) => err.fmt(f),
17 GcloudTraceError::NetworkError(ref err) => err.fmt(f),
18 }
19 }
20}
21
22impl std::error::Error for GcloudTraceError {
23 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
24 match *self {
25 GcloudTraceError::SystemError(ref err) => Some(err),
26 GcloudTraceError::NetworkError(ref err) => Some(err),
27 }
28 }
29}
30
31#[derive(Debug, Builder)]
32pub struct GcloudTraceSystemError {
33 pub message: String,
34 pub root_cause: Option<BoxedError>,
35}
36
37impl std::fmt::Display for GcloudTraceSystemError {
38 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
39 write!(f, "System error: {:?}", self.message)
40 }
41}
42
43impl std::error::Error for GcloudTraceSystemError {}
44
45#[derive(Debug, Eq, PartialEq, Clone, Builder)]
46pub struct GcloudTraceNetworkError {
47 pub message: String,
48}
49
50impl std::fmt::Display for GcloudTraceNetworkError {
51 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52 write!(f, "Network error: {}", self.message)
53 }
54}
55
56impl std::error::Error for GcloudTraceNetworkError {}
57
58impl From<gcloud_sdk::error::Error> for GcloudTraceError {
59 fn from(gcloud_error: Error) -> Self {
60 GcloudTraceError::SystemError(
61 GcloudTraceSystemError::new(format!("Google SDK error: {gcloud_error}"))
62 .with_root_cause(Box::new(gcloud_error)),
63 )
64 }
65}
66
67impl From<gcloud_sdk::tonic::Status> for GcloudTraceError {
68 fn from(status: gcloud_sdk::tonic::Status) -> Self {
69 GcloudTraceError::NetworkError(GcloudTraceNetworkError::new(format!("{status}")))
70 }
71}
72
73impl ExportError for GcloudTraceError {
74 fn exporter_name(&self) -> &'static str {
75 "GoogleCloudTraceExporter"
76 }
77}