Skip to content

Commit 6289fee

Browse files
committed
refactor: use thiserror to shorten code, even though it duplicates error messages
1 parent a0b4576 commit 6289fee

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libdd-profiling-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ hyper = { workspace = true}
5656
libc = "0.2"
5757
serde_json = { version = "1.0" }
5858
symbolizer-ffi = { path = "../symbolizer-ffi", optional = true, default-features = false }
59+
thiserror = "2"
5960
tokio-util = "0.7.1"
6061
datadog-ffe-ffi = { path = "../datadog-ffe-ffi", default-features = false, optional = true }

libdd-profiling-ffi/src/profiles/utf8.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,14 @@ pub enum Utf8Option {
2525
}
2626

2727
#[allow(dead_code)]
28-
#[derive(Debug)]
28+
#[derive(thiserror::Error, Debug)]
2929
pub enum Utf8ConversionError {
30-
OutOfMemory(TryReserveError),
31-
SliceConversionError(SliceConversionError),
32-
Utf8Error(Utf8Error),
33-
}
34-
35-
impl From<TryReserveError> for Utf8ConversionError {
36-
fn from(e: TryReserveError) -> Self {
37-
Self::OutOfMemory(e)
38-
}
39-
}
40-
41-
impl From<SliceConversionError> for Utf8ConversionError {
42-
fn from(e: SliceConversionError) -> Self {
43-
Self::SliceConversionError(e)
44-
}
45-
}
46-
47-
impl From<Utf8Error> for Utf8ConversionError {
48-
fn from(e: Utf8Error) -> Self {
49-
Self::Utf8Error(e)
50-
}
30+
#[error("out of memory: utf8 conversion failed")]
31+
OutOfMemory(#[from] TryReserveError),
32+
#[error(transparent)]
33+
SliceConversionError(#[from] SliceConversionError),
34+
#[error("invalid input: string was not utf-8")]
35+
Utf8Error(#[from] Utf8Error),
5136
}
5237

5338
// SAFETY: all cases are c-str literals, or delegate to the same trait.

0 commit comments

Comments
 (0)