Skip to content

Commit

Permalink
Inspect error message
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Aug 20, 2022
1 parent bee215a commit b8f9aad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions onnxruntime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions onnxruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ to download.

use std::{
ffi::c_void,
fmt::{self, Debug},
ptr::null_mut,
sync::{atomic::AtomicPtr, Arc, Mutex},
};
Expand Down Expand Up @@ -193,6 +194,21 @@ fn g_ort() -> sys::OrtApi {
fn char_p_to_string(raw: *const i8) -> Result<String> {
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)),
Expand Down

0 comments on commit b8f9aad

Please sign in to comment.