| 5334 | } |
| 5335 | |
| 5336 | pub fn deserialize_error_lenient(serialized_string: &str, error_msg: &str) { |
| 5337 | use std::panic::catch_unwind; |
| 5338 | panic::set_hook(Box::new(|_info| { |
| 5339 | // See: https://stackoverflow.com/questions/35559267/suppress-panic-output-in-rust-when-using-paniccatch-unwind |
| 5340 | })); |
| 5341 | let result = catch_unwind(|| serde_json::from_str::<Context>(serialized_string).unwrap()); |
| 5342 | // This is a (nasty) hack. |
| 5343 | // We check whether the returned error contain the expected error message. |
| 5344 | use ciphercore_utils::execute_main::extract_panic_message; |
| 5345 | if let Err(e) = result { |
| 5346 | match extract_panic_message(e) { |
| 5347 | Some(msg) => { |
| 5348 | if !msg.contains(error_msg) { |
| 5349 | panic!("Undesirable panic: {}", msg); |
| 5350 | } |
| 5351 | } |
| 5352 | None => panic!("Panic of unknown type"), |
| 5353 | } |
| 5354 | } else { |
| 5355 | panic!("Expected error not occur") |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | use std::{ |
| 5360 | fs::File, |