Skip to content

Commit 7eb64b3

Browse files
committed
simplify libexec implementation
1 parent dcfcb2c commit 7eb64b3

File tree

4 files changed

+251
-345
lines changed

4 files changed

+251
-345
lines changed

bear/src/intercept/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ pub fn create_reporter() -> anyhow::Result<Box<dyn Reporter>> {
3838
std::env::var(KEY_DESTINATION)
3939
.with_context(|| format!("${} is missing from the environment", KEY_DESTINATION))
4040
// Create a new reporter
41-
.and_then(tcp::ReporterOnTcp::new)?;
41+
.map(tcp::ReporterOnTcp::new)?;
4242
Ok(Box::new(reporter))
4343
}
4444

45-
pub fn create_reporter_on_tcp(address: &str) -> anyhow::Result<Box<dyn Reporter>> {
46-
let reporter = tcp::ReporterOnTcp::new(address.to_string())?;
47-
Ok(Box::new(reporter))
45+
pub fn create_reporter_on_tcp(address: &str) -> Box<dyn Reporter> {
46+
let reporter = tcp::ReporterOnTcp::new(address.to_string());
47+
Box::new(reporter)
4848
}
4949

5050
/// Represents the remote sink of supervised process events.

bear/src/intercept/tcp.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ impl ReporterOnTcp {
135135
///
136136
/// It does not open the TCP connection yet. Stores the destination
137137
/// address and creates a unique reporter id.
138-
pub fn new(destination: String) -> Result<Self, anyhow::Error> {
139-
let result = ReporterOnTcp { destination };
140-
Ok(result)
138+
pub fn new(destination: String) -> Self {
139+
ReporterOnTcp { destination }
141140
}
142141
}
143142

@@ -192,7 +191,7 @@ mod tests {
192191
#[test]
193192
fn tcp_reporter_and_collectors_work() {
194193
let collector = CollectorOnTcp::create().unwrap();
195-
let reporter = ReporterOnTcp::new(collector.address()).unwrap();
194+
let reporter = ReporterOnTcp::new(collector.address());
196195

197196
// Create wrapper to share the collector across threads.
198197
let thread_collector = Arc::new(collector);

intercept-preload/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ crate-type = ["rlib", "cdylib"]
1818
[dependencies]
1919
bear = { path = "../bear" }
2020
thiserror.workspace = true
21-
anyhow.workspace = true
2221
log.workspace = true
22+
env_logger.workspace = true
23+
ctor = { version = "0.4" }
2324

2425
[target.'cfg(target_os = "linux")'.dependencies]
2526
libc.workspace = true

0 commit comments

Comments
 (0)