Skip to content

Commit ce676f3

Browse files
authored
Wrap ffi calls with catch_unwind. (#1083)
* Wrap ffi calls with catch_unwind. * Add guard in case panic is change to abort. * Add error logging while catching panics.
1 parent b55370c commit ce676f3

File tree

4 files changed

+267
-173
lines changed

4 files changed

+267
-173
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.

data-pipeline-ffi/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ crate-type = ["lib", "staticlib", "cdylib"]
1515
bench = false
1616

1717
[features]
18-
default = ["cbindgen"]
18+
default = ["cbindgen", "catch_panic"]
19+
catch_panic = []
1920
cbindgen = ["build_common/cbindgen", "ddcommon-ffi/cbindgen"]
2021

2122
[build-dependencies]
@@ -30,3 +31,4 @@ datadog-trace-utils = { path = "../datadog-trace-utils" }
3031
data-pipeline = { path = "../data-pipeline" }
3132
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
3233
tinybytes = { path = "../tinybytes" }
34+
tracing = { version = "0.1", default-features = false }

data-pipeline-ffi/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum ExporterErrorCode {
3333
Serde,
3434
TimedOut,
3535
Internal,
36+
#[cfg(feature = "catch_panic")]
37+
Panic,
3638
}
3739

3840
impl Display for ExporterErrorCode {
@@ -59,6 +61,8 @@ impl Display for ExporterErrorCode {
5961
Self::Serde => write!(f, "Serialization/Deserialization error"),
6062
Self::TimedOut => write!(f, "Operation timed out"),
6163
Self::Internal => write!(f, "Internal error"),
64+
#[cfg(feature = "catch_panic")]
65+
Self::Panic => write!(f, "Operation panicked"),
6266
}
6367
}
6468
}

0 commit comments

Comments
 (0)