Skip to content

Commit 20c9bb8

Browse files
committed
FIXUP: make templates more template-y
1 parent 045d040 commit 20c9bb8

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

data-pipeline-ffi/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod tests {
353353
assert_eq!(ffi_error.code, ExporterErrorCode::InvalidUrl);
354354
assert!(!ffi_error.msg_template.is_null());
355355
let template_str = unsafe { CStr::from_ptr(ffi_error.msg_template).to_string_lossy() };
356-
assert_eq!(template_str, "Invalid URI provided");
356+
assert_eq!(template_str, "Invalid URI provided: {details}");
357357
assert!(!ffi_error.context_fields.is_null());
358358
assert_eq!(ffi_error.context_count, 1);
359359

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

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

@@ -656,7 +660,7 @@ mod tests {
656660
#[test]
657661
fn test_builder_error_template() {
658662
let error = BuilderErrorKind::InvalidUri("invalid://url".to_string());
659-
assert_eq!(error.template(), "Invalid URI provided");
663+
assert_eq!(error.template(), "Invalid URI provided: {details}");
660664
let context = error.context();
661665
assert_eq!(context.fields().len(), 1);
662666
assert_eq!(
@@ -665,7 +669,10 @@ mod tests {
665669
);
666670

667671
let error = BuilderErrorKind::InvalidTelemetryConfig("missing field".to_string());
668-
assert_eq!(error.template(), "Invalid telemetry configuration");
672+
assert_eq!(
673+
error.template(),
674+
"Invalid telemetry configuration: {details}"
675+
);
669676
let context = error.context();
670677
assert_eq!(context.fields().len(), 1);
671678
assert_eq!(
@@ -674,7 +681,7 @@ mod tests {
674681
);
675682

676683
let error = BuilderErrorKind::InvalidConfiguration("bad setting".to_string());
677-
assert_eq!(error.template(), "Invalid configuration");
684+
assert_eq!(error.template(), "Invalid configuration: {details}");
678685
let context = error.context();
679686
assert_eq!(context.fields().len(), 1);
680687
assert_eq!(
@@ -686,7 +693,10 @@ mod tests {
686693
#[test]
687694
fn test_internal_error_template() {
688695
let error = InternalErrorKind::InvalidWorkerState("worker crashed".to_string());
689-
assert_eq!(error.template(), "Background worker in invalid state");
696+
assert_eq!(
697+
error.template(),
698+
"Background worker in invalid state: {details}"
699+
);
690700
let context = error.context();
691701
assert_eq!(context.fields().len(), 1);
692702
assert_eq!(
@@ -760,7 +770,10 @@ mod tests {
760770
#[test]
761771
fn test_request_error_template() {
762772
let error = RequestError::new(StatusCode::NOT_FOUND, "Resource not found");
763-
assert_eq!(error.template(), "Agent responded with error status");
773+
assert_eq!(
774+
error.template(),
775+
"Agent responded with error status {status_code}: {response}"
776+
);
764777
let context = error.context();
765778
assert_eq!(context.fields().len(), 2);
766779
assert_eq!(
@@ -773,7 +786,10 @@ mod tests {
773786
);
774787

775788
let error = RequestError::new(StatusCode::INTERNAL_SERVER_ERROR, "Server error");
776-
assert_eq!(error.template(), "Agent responded with error status");
789+
assert_eq!(
790+
error.template(),
791+
"Agent responded with error status {status_code}: {response}"
792+
);
777793
let context = error.context();
778794
assert_eq!(context.fields().len(), 2);
779795
assert_eq!(
@@ -791,7 +807,10 @@ mod tests {
791807
use std::time::Duration;
792808

793809
let error = ShutdownError::TimedOut(Duration::from_secs(5));
794-
assert_eq!(error.template(), "Shutdown operation timed out");
810+
assert_eq!(
811+
error.template(),
812+
"Shutdown operation timed out after {timeout_seconds} seconds"
813+
);
795814
let context = error.context();
796815
assert_eq!(context.fields().len(), 1);
797816
assert_eq!(
@@ -800,7 +819,10 @@ mod tests {
800819
);
801820

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

0 commit comments

Comments
 (0)