Skip to content

Commit bbcfc57

Browse files
DataViewer::execution_thread() protect from panics (#24)
* execution_thread safer from panic * remove log duplication * local not used * save the closure * + try_local! macro * actuallt local!() is good enough and gives the same syntax as the try block * rm junk
1 parent fbd8610 commit bbcfc57

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

crates/ark/src/data_viewer/r_data_viewer.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use libR_sys::VECTOR_ELT;
3535
use libR_sys::XLENGTH;
3636
use serde::Deserialize;
3737
use serde::Serialize;
38+
use stdext::local;
3839
use stdext::spawn;
3940
use uuid::Uuid;
4041

@@ -235,19 +236,22 @@ impl RDataViewer {
235236
}
236237

237238
pub fn execution_thread(self) {
238-
// This is a simplistic version where all the data is converted as once to
239-
// a message that is included in initial event of the comm.
240-
let json = match DataSet::from_object(self.id.clone(), self.title.clone(), self.data) {
241-
Ok(data_set) => serde_json::to_value(data_set).unwrap(),
242-
Err(error) => {
243-
log::error!("Error while viewing object '{}': {}", self.title, error);
244-
return;
245-
},
239+
let execute: Result<(), anyhow::Error> = local! {
240+
// This is a simplistic version where all the data is converted as once to
241+
// a message that is included in initial event of the comm.
242+
let data_set = DataSet::from_object(self.id.clone(), self.title.clone(), self.data)?;
243+
let json = serde_json::to_value(data_set)?;
244+
245+
let comm_manager_tx = comm_manager_tx();
246+
let event = CommEvent::Opened(self.comm.clone(), json);
247+
comm_manager_tx.send(event)?;
248+
249+
Ok(())
246250
};
247251

248-
let comm_manager_tx = comm_manager_tx();
249-
let event = CommEvent::Opened(self.comm.clone(), json);
250-
comm_manager_tx.send(event).unwrap();
252+
if let Err(error) = execute {
253+
log::error!("Error while viewing object '{}': {}", self.title, error);
254+
}
251255
}
252256
}
253257

0 commit comments

Comments
 (0)