Skip to content

Commit 9e8efac

Browse files
committed
FIXUP: make templates more template-y
1 parent ed33de8 commit 9e8efac

File tree

2 files changed

+58
-36
lines changed
  • libdd-data-pipeline-ffi/src
  • libdd-data-pipeline/src/trace_exporter

2 files changed

+58
-36
lines changed

libdd-data-pipeline-ffi/src/error.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use libdd_data_pipeline::trace_exporter::error::{
5-
AgentErrorKind, BuilderErrorKind, InternalErrorKind, NetworkErrorKind, TraceExporterError,
5+
AgentErrorKind, BuilderErrorKind, NetworkErrorKind, TraceExporterError,
66
};
77
use std::ffi::{c_char, CString};
88
use std::fmt::Display;
@@ -164,35 +164,35 @@ impl From<TraceExporterError> for ExporterError {
164164
let code = match &value {
165165
TraceExporterError::Agent(_) => ExporterErrorCode::HttpEmptyBody,
166166
TraceExporterError::Builder(builder_error) => match builder_error {
167-
data_pipeline::trace_exporter::error::BuilderErrorKind::InvalidUri(_) => {
167+
BuilderErrorKind::InvalidUri(_) => {
168168
ExporterErrorCode::InvalidUrl
169169
}
170170
_ => ExporterErrorCode::InvalidArgument,
171171
},
172172
TraceExporterError::Internal(_) => ExporterErrorCode::Internal,
173173
TraceExporterError::Network(network_error) => match network_error.kind() {
174-
data_pipeline::trace_exporter::error::NetworkErrorKind::Body => {
174+
NetworkErrorKind::Body => {
175175
ExporterErrorCode::HttpBodyFormat
176176
}
177-
data_pipeline::trace_exporter::error::NetworkErrorKind::Parse => {
177+
NetworkErrorKind::Parse => {
178178
ExporterErrorCode::HttpParse
179179
}
180-
data_pipeline::trace_exporter::error::NetworkErrorKind::TimedOut => {
180+
NetworkErrorKind::TimedOut => {
181181
ExporterErrorCode::TimedOut
182182
}
183-
data_pipeline::trace_exporter::error::NetworkErrorKind::WrongStatus => {
183+
NetworkErrorKind::WrongStatus => {
184184
ExporterErrorCode::HttpWrongStatus
185185
}
186-
data_pipeline::trace_exporter::error::NetworkErrorKind::ConnectionClosed => {
186+
NetworkErrorKind::ConnectionClosed => {
187187
ExporterErrorCode::ConnectionReset
188188
}
189-
data_pipeline::trace_exporter::error::NetworkErrorKind::MessageTooLarge => {
189+
NetworkErrorKind::MessageTooLarge => {
190190
ExporterErrorCode::HttpBodyTooLong
191191
}
192-
data_pipeline::trace_exporter::error::NetworkErrorKind::Canceled => {
192+
NetworkErrorKind::Canceled => {
193193
ExporterErrorCode::HttpClient
194194
}
195-
data_pipeline::trace_exporter::error::NetworkErrorKind::Unknown => {
195+
NetworkErrorKind::Unknown => {
196196
ExporterErrorCode::NetworkUnknown
197197
}
198198
},
@@ -346,7 +346,7 @@ mod tests {
346346

347347
#[test]
348348
fn from_trace_exporter_error_builder_test() {
349-
use data_pipeline::trace_exporter::error::{BuilderErrorKind, TraceExporterError};
349+
use libdd_data_pipeline::trace_exporter::error::{BuilderErrorKind, TraceExporterError};
350350

351351
let builder_error =
352352
TraceExporterError::Builder(BuilderErrorKind::InvalidUri("bad://url".to_string()));
@@ -355,7 +355,7 @@ mod tests {
355355
assert_eq!(ffi_error.code, ExporterErrorCode::InvalidUrl);
356356
assert!(!ffi_error.msg_template.is_null());
357357
let template_str = unsafe { CStr::from_ptr(ffi_error.msg_template).to_string_lossy() };
358-
assert_eq!(template_str, "Invalid URI provided");
358+
assert_eq!(template_str, "Invalid URI provided: {details}");
359359
assert!(!ffi_error.context_fields.is_null());
360360
assert_eq!(ffi_error.context_count, 1);
361361

@@ -369,7 +369,7 @@ mod tests {
369369

370370
#[test]
371371
fn from_trace_exporter_error_network_test() {
372-
use data_pipeline::trace_exporter::error::TraceExporterError;
372+
use libdd_data_pipeline::trace_exporter::error::TraceExporterError;
373373
use std::io::{Error as IoError, ErrorKind};
374374

375375
// Create a network error by wrapping an IO error
@@ -387,7 +387,7 @@ mod tests {
387387

388388
#[test]
389389
fn from_trace_exporter_error_agent_test() {
390-
use data_pipeline::trace_exporter::error::{AgentErrorKind, TraceExporterError};
390+
use libdd_data_pipeline::trace_exporter::error::{AgentErrorKind, TraceExporterError};
391391

392392
let agent_error = TraceExporterError::Agent(AgentErrorKind::EmptyResponse);
393393
let ffi_error = ExporterError::from(agent_error);
@@ -402,7 +402,7 @@ mod tests {
402402

403403
#[test]
404404
fn from_trace_exporter_error_without_template_test() {
405-
use data_pipeline::trace_exporter::error::TraceExporterError;
405+
use libdd_data_pipeline::trace_exporter::error::TraceExporterError;
406406
use std::io::{Error as IoError, ErrorKind};
407407

408408
let io_error =
@@ -419,7 +419,7 @@ mod tests {
419419

420420
#[test]
421421
fn from_trace_exporter_error_memory_safety_test() {
422-
use data_pipeline::trace_exporter::error::{BuilderErrorKind, TraceExporterError};
422+
use libdd_data_pipeline::trace_exporter::error::{BuilderErrorKind, TraceExporterError};
423423

424424
// Create error with context
425425
let builder_error = TraceExporterError::Builder(BuilderErrorKind::InvalidConfiguration(

libdd-data-pipeline/src/trace_exporter/error.rs

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ pub enum BuilderErrorKind {
9191
}
9292

9393
impl BuilderErrorKind {
94-
const INVALID_URI_TEMPLATE: &'static str = "Invalid URI provided";
95-
const INVALID_TELEMETRY_CONFIG_TEMPLATE: &'static str = "Invalid telemetry configuration";
96-
const INVALID_CONFIGURATION_TEMPLATE: &'static str = "Invalid configuration";
94+
const INVALID_URI_TEMPLATE: &'static str = "Invalid URI provided: {details}";
95+
const INVALID_TELEMETRY_CONFIG_TEMPLATE: &'static str =
96+
"Invalid telemetry configuration: {details}";
97+
const INVALID_CONFIGURATION_TEMPLATE: &'static str = "Invalid configuration: {details}";
9798
}
9899

99100
impl Display for BuilderErrorKind {
@@ -143,7 +144,8 @@ pub enum InternalErrorKind {
143144
}
144145

145146
impl InternalErrorKind {
146-
const INVALID_WORKER_STATE_TEMPLATE: &'static str = "Background worker in invalid state";
147+
const INVALID_WORKER_STATE_TEMPLATE: &'static str =
148+
"Background worker in invalid state: {details}";
147149
}
148150

149151
impl Display for InternalErrorKind {
@@ -274,7 +276,8 @@ pub struct RequestError {
274276
}
275277

276278
impl RequestError {
277-
const REQUEST_ERROR_TEMPLATE: &'static str = "Agent responded with error status";
279+
const REQUEST_ERROR_TEMPLATE: &'static str =
280+
"Agent responded with error status {status_code}: {response}";
278281
}
279282

280283
impl Display for RequestError {
@@ -322,7 +325,8 @@ pub enum ShutdownError {
322325
}
323326

324327
impl ShutdownError {
325-
const TIMED_OUT_TEMPLATE: &'static str = "Shutdown operation timed out";
328+
const TIMED_OUT_TEMPLATE: &'static str =
329+
"Shutdown operation timed out after {timeout_seconds} seconds";
326330
}
327331

328332
impl Display for ShutdownError {
@@ -352,11 +356,11 @@ impl ErrorTemplate for ShutdownError {
352356
impl ErrorTemplate for DecodeError {
353357
fn template(&self) -> &'static str {
354358
match self {
355-
DecodeError::InvalidConversion(_) => "Failed to convert decoded value",
356-
DecodeError::InvalidType(_) => "Invalid type in trace payload",
357-
DecodeError::InvalidFormat(_) => "Invalid msgpack format",
359+
DecodeError::InvalidConversion(_) => "Failed to convert decoded value: {details}",
360+
DecodeError::InvalidType(_) => "Invalid type in trace payload: {details}",
361+
DecodeError::InvalidFormat(_) => "Invalid msgpack format: {details}",
358362
DecodeError::IOError => "Failed to read from buffer",
359-
DecodeError::Utf8Error(_) => "Failed to decode UTF-8 string",
363+
DecodeError::Utf8Error(_) => "Failed to decode UTF-8 string: {details}",
360364
}
361365
}
362366

@@ -575,8 +579,8 @@ impl ErrorTemplate for TraceExporterError {
575579
TraceExporterError::Shutdown(e) => e.template(),
576580
TraceExporterError::Deserialization(e) => e.template(),
577581
TraceExporterError::Io(io_error) => Self::io_error_template(io_error),
578-
TraceExporterError::Telemetry(_) => "Telemetry operation failed",
579-
TraceExporterError::Serialization(_) => "Failed to serialize data",
582+
TraceExporterError::Telemetry(_) => "Telemetry operation failed: {details}",
583+
TraceExporterError::Serialization(_) => "Failed to serialize data: {details}",
580584
}
581585
}
582586

@@ -657,7 +661,7 @@ mod tests {
657661
#[test]
658662
fn test_builder_error_template() {
659663
let error = BuilderErrorKind::InvalidUri("invalid://url".to_string());
660-
assert_eq!(error.template(), "Invalid URI provided");
664+
assert_eq!(error.template(), "Invalid URI provided: {details}");
661665
let context = error.context();
662666
assert_eq!(context.fields().len(), 1);
663667
assert_eq!(
@@ -666,7 +670,10 @@ mod tests {
666670
);
667671

668672
let error = BuilderErrorKind::InvalidTelemetryConfig("missing field".to_string());
669-
assert_eq!(error.template(), "Invalid telemetry configuration");
673+
assert_eq!(
674+
error.template(),
675+
"Invalid telemetry configuration: {details}"
676+
);
670677
let context = error.context();
671678
assert_eq!(context.fields().len(), 1);
672679
assert_eq!(
@@ -675,7 +682,7 @@ mod tests {
675682
);
676683

677684
let error = BuilderErrorKind::InvalidConfiguration("bad setting".to_string());
678-
assert_eq!(error.template(), "Invalid configuration");
685+
assert_eq!(error.template(), "Invalid configuration: {details}");
679686
let context = error.context();
680687
assert_eq!(context.fields().len(), 1);
681688
assert_eq!(
@@ -687,7 +694,10 @@ mod tests {
687694
#[test]
688695
fn test_internal_error_template() {
689696
let error = InternalErrorKind::InvalidWorkerState("worker crashed".to_string());
690-
assert_eq!(error.template(), "Background worker in invalid state");
697+
assert_eq!(
698+
error.template(),
699+
"Background worker in invalid state: {details}"
700+
);
691701
let context = error.context();
692702
assert_eq!(context.fields().len(), 1);
693703
assert_eq!(
@@ -761,7 +771,10 @@ mod tests {
761771
#[test]
762772
fn test_request_error_template() {
763773
let error = RequestError::new(StatusCode::NOT_FOUND, "Resource not found");
764-
assert_eq!(error.template(), "Agent responded with error status");
774+
assert_eq!(
775+
error.template(),
776+
"Agent responded with error status {status_code}: {response}"
777+
);
765778
let context = error.context();
766779
assert_eq!(context.fields().len(), 2);
767780
assert_eq!(
@@ -774,7 +787,10 @@ mod tests {
774787
);
775788

776789
let error = RequestError::new(StatusCode::INTERNAL_SERVER_ERROR, "Server error");
777-
assert_eq!(error.template(), "Agent responded with error status");
790+
assert_eq!(
791+
error.template(),
792+
"Agent responded with error status {status_code}: {response}"
793+
);
778794
let context = error.context();
779795
assert_eq!(context.fields().len(), 2);
780796
assert_eq!(
@@ -792,7 +808,10 @@ mod tests {
792808
use std::time::Duration;
793809

794810
let error = ShutdownError::TimedOut(Duration::from_secs(5));
795-
assert_eq!(error.template(), "Shutdown operation timed out");
811+
assert_eq!(
812+
error.template(),
813+
"Shutdown operation timed out after {timeout_seconds} seconds"
814+
);
796815
let context = error.context();
797816
assert_eq!(context.fields().len(), 1);
798817
assert_eq!(
@@ -801,7 +820,10 @@ mod tests {
801820
);
802821

803822
let error = ShutdownError::TimedOut(Duration::from_millis(2500));
804-
assert_eq!(error.template(), "Shutdown operation timed out");
823+
assert_eq!(
824+
error.template(),
825+
"Shutdown operation timed out after {timeout_seconds} seconds"
826+
);
805827
let context = error.context();
806828
assert_eq!(context.fields().len(), 1);
807829
assert_eq!(

0 commit comments

Comments
 (0)