Skip to content

Commit 19af650

Browse files
committed
undo re-introduced unwrap()s
1 parent 90b09ed commit 19af650

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/pyroscope.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl PyroscopeConfig {
6363
/// ```ignore
6464
/// let mut config = PyroscopeConfig::new("http://localhost:8080", "my-app");
6565
/// config.set_sample_rate(10)
66-
/// .unwrap();
66+
/// ?;
6767
/// ```
6868
pub fn sample_rate(self, sample_rate: i32) -> Self {
6969
Self {
@@ -77,8 +77,7 @@ impl PyroscopeConfig {
7777
/// ```ignore
7878
/// use pyroscope::pyroscope::PyroscopeConfig;
7979
/// let config = PyroscopeConfig::new("http://localhost:8080", "my-app")
80-
/// .tags(vec![("env", "dev")])
81-
/// .unwrap();
80+
/// .tags(vec![("env", "dev")])?;
8281
/// ```
8382
pub fn tags(self, tags: &[(&str, &str)]) -> Self {
8483
// Convert &[(&str, &str)] to HashMap(String, String)
@@ -105,7 +104,7 @@ impl PyroscopeConfig {
105104
/// ```ignore
106105
/// use pyroscope::pyroscope::PyroscopeAgentBuilder;
107106
/// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app");
108-
/// let agent = builder.build().unwrap();
107+
/// let agent = builder.build()?;
109108
/// ```
110109
pub struct PyroscopeAgentBuilder {
111110
/// Profiler backend
@@ -135,7 +134,7 @@ impl PyroscopeAgentBuilder {
135134
/// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
136135
/// .backend(Pprof::default())
137136
/// .build()
138-
/// .unwrap();
137+
/// ?;
139138
/// ```
140139
pub fn backend<T>(self, backend: T) -> Self
141140
where T: 'static + Backend {
@@ -151,7 +150,7 @@ impl PyroscopeAgentBuilder {
151150
/// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
152151
/// .sample_rate(99)
153152
/// .build()
154-
/// .unwrap();
153+
/// ?;
155154
/// ```
156155
pub fn sample_rate(self, sample_rate: i32) -> Self {
157156
Self {
@@ -166,7 +165,7 @@ impl PyroscopeAgentBuilder {
166165
/// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
167166
/// .tags(vec![("env", "dev")])
168167
/// .build()
169-
/// .unwrap();
168+
/// ?;
170169
/// ```
171170
pub fn tags(self, tags: &[(&str, &str)]) -> Self {
172171
Self {
@@ -231,9 +230,11 @@ impl Drop for PyroscopeAgent {
231230
}
232231

233232
// Wait for the Timer thread to finish
234-
match self.timer.handle.take().unwrap().join() {
235-
Ok(_) => log::trace!(target: LOG_TAG, "Dropped timer thread"),
236-
Err(_) => log::error!(target: LOG_TAG, "Error Dropping timer thread"),
233+
if let Some(handle) = self.timer.handle.take() {
234+
match handle.join() {
235+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped timer thread"),
236+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping timer thread"),
237+
}
237238
}
238239

239240
// Stop the SessionManager
@@ -242,16 +243,20 @@ impl Drop for PyroscopeAgent {
242243
Err(_) => log::error!(target: LOG_TAG, "Error sending kill signal to SessionManager"),
243244
}
244245

245-
// Stop SessionManager
246-
match self.session_manager.handle.take().unwrap().join() {
247-
Ok(_) => log::trace!(target: LOG_TAG, "Dropped SessionManager thread"),
248-
Err(_) => log::error!(target: LOG_TAG, "Error Dropping SessionManager thread"),
246+
if let Some(handle) = self.session_manager.handle.take() {
247+
match handle.join() {
248+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped SessionManager thread"),
249+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping SessionManager thread"),
250+
}
249251
}
250252

251253
// Wait for main thread to finish
252-
match self.handle.take().unwrap().join() {
253-
Ok(_) => log::trace!(target: LOG_TAG, "Dropped main thread"),
254-
Err(_) => log::error!(target: LOG_TAG, "Error Dropping main thread"),
254+
255+
if let Some(handle) = self.handle.take() {
256+
match handle.join() {
257+
Ok(_) => log::trace!(target: LOG_TAG, "Dropped main thread"),
258+
Err(_) => log::error!(target: LOG_TAG, "Error Dropping main thread"),
259+
}
255260
}
256261

257262
log::debug!(target: LOG_TAG, "Agent Dropped");
@@ -263,7 +268,7 @@ impl PyroscopeAgent {
263268
///
264269
/// # Example
265270
/// ```ignore
266-
/// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build().unwrap();
271+
/// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()?;
267272
/// ```
268273
pub fn builder<S: AsRef<str>>(url: S, application_name: S) -> PyroscopeAgentBuilder {
269274
// Build PyroscopeAgent
@@ -296,20 +301,20 @@ impl PyroscopeAgent {
296301
self.handle = Some(std::thread::spawn(move || {
297302
log::trace!(target: LOG_TAG, "Main Thread started");
298303

299-
while let Ok(time) = rx.recv() {
300-
log::trace!(target: LOG_TAG, "Sending session {}", time);
304+
while let Ok(until) = rx.recv() {
305+
log::trace!(target: LOG_TAG, "Sending session {}", until);
301306

302307
// Generate report from backend
303308
let report = backend.lock()?.report()?;
304309

305310
// Send new Session to SessionManager
306311
stx.send(SessionSignal::Session(Session::new(
307-
time,
312+
until,
308313
config.clone(),
309314
report,
310315
)?))?;
311316

312-
if time == 0 {
317+
if until == 0 {
313318
log::trace!(target: LOG_TAG, "Session Killed");
314319

315320
let (lock, cvar) = &*pair;
@@ -329,7 +334,7 @@ impl PyroscopeAgent {
329334
/// Start profiling and sending data. The agent will keep running until stopped. The agent will send data to the server every 10s secondy.
330335
/// # Example
331336
/// ```ignore
332-
/// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build().unwrap();
337+
/// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()?;
333338
/// agent.start();
334339
/// ```
335340
pub fn start(&mut self) {

0 commit comments

Comments
 (0)