Make it more obvious where the Go test flake is coming from
@@ -50,11 +50,11 @@ macro_rules! ffi_try {
}
thread_local! {
- static LAST_ERROR: Mutex<Option<Box<error::PolarError>>> = Default::default();
+ static LAST_ERROR: Mutex<Option<error::PolarError>> = Default::default();
}
fn set_error(e: error::PolarError) -> i32 {
- LAST_ERROR.with(|prev| *prev.lock().unwrap() = Some(Box::new(e)));
+ LAST_ERROR.with(|prev| *prev.lock().unwrap() = Some(e));
POLAR_FAILURE
}
@@ -62,14 +62,16 @@ fn set_error(e: error::PolarError) -> i32 {
pub extern "C" fn polar_get_error() -> *const c_char {
ffi_try!({
let err = LAST_ERROR.with(|prev| prev.lock().unwrap().take());
- if let Some(e) = err {
- let error_json = serde_json::to_string(&e).unwrap();
+ let err = err.unwrap_or_else(|| error::PolarError {
+ kind: error::ErrorKind::Runtime(error::RuntimeError::InvalidState {
+ msg: "attempting to fetch an error, but no error is present".to_string(),
+ }),
+ context: None,
+ });
+ let error_json = serde_json::to_string(&err).unwrap();
CString::new(error_json)
.expect("JSON should not contain any 0 bytes")
.into_raw()
- } else {
- null()
- }
})
}
