From b8f9aad523e412a270e3a0e53cd61c9f65e5f93d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 20 Aug 2022 10:30:54 +0900 Subject: [PATCH] Inspect error message --- onnxruntime/Cargo.toml | 2 ++ onnxruntime/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/onnxruntime/Cargo.toml b/onnxruntime/Cargo.toml index 8bdc6cca..304b014c 100644 --- a/onnxruntime/Cargo.toml +++ b/onnxruntime/Cargo.toml @@ -28,6 +28,8 @@ tracing = "0.1" # Enabled with 'model-fetching' feature ureq = { version = "2.1", optional = true } +base64 = "0.13.0" +encoding_rs = "0.8.31" [dev-dependencies] image = "0.23" diff --git a/onnxruntime/src/lib.rs b/onnxruntime/src/lib.rs index 0320157a..b8600011 100644 --- a/onnxruntime/src/lib.rs +++ b/onnxruntime/src/lib.rs @@ -117,6 +117,7 @@ to download. use std::{ ffi::c_void, + fmt::{self, Debug}, ptr::null_mut, sync::{atomic::AtomicPtr, Arc, Mutex}, }; @@ -193,6 +194,21 @@ fn g_ort() -> sys::OrtApi { fn char_p_to_string(raw: *const i8) -> Result { let c_string = unsafe { std::ffi::CStr::from_ptr(raw as *mut i8).to_owned() }; + if c_string.to_str().is_err() { + struct Base64<'a>(&'a [u8]); + + impl Debug for Base64<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", base64::encode(self.0)) + } + } + + let error_message = c_string.to_bytes(); + dbg!(Base64(error_message)); + dbg!(String::from_utf8_lossy(error_message)); + dbg!(encoding_rs::SHIFT_JIS.decode(error_message).0); + } + match c_string.into_string() { Ok(string) => Ok(string), Err(e) => Err(OrtApiError::IntoStringError(e)),