From b0aa0ce20ea4920855a49f9a3439032250f83bba Mon Sep 17 00:00:00 2001 From: "andries@fam-hiemstra.nl" Date: Tue, 15 Oct 2024 13:07:26 +0200 Subject: [PATCH] don't panic on utf8 error --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- src/quickjs_utils/primitives.rs | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a25429400..703678fd0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.14.4 + +* don't panic on utf8 error in to_str + # 0.14.3 * update quickjs-ng to 0.6.0 diff --git a/Cargo.toml b/Cargo.toml index 562dd132dc..64a28ad476 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quickjs_runtime" -version = "0.14.3" +version = "0.14.4" authors = ["Andries Hiemstra "] edition = "2021" description = "Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await" diff --git a/src/quickjs_utils/primitives.rs b/src/quickjs_utils/primitives.rs index dfab244d8e..9d4e8ee1f3 100644 --- a/src/quickjs_utils/primitives.rs +++ b/src/quickjs_utils/primitives.rs @@ -124,7 +124,8 @@ pub unsafe fn to_str( } let cstr = std::ffi::CStr::from_ptr(ptr); - Ok(cstr.to_str().expect("bad cstr bad!")) + cstr.to_str() + .map_err(|e| JsError::new_string(format!("utf8 error: {e}"))) //let s = cstr.to_string_lossy();