From 6890f58a038b104d57b2885e5ba7bd07074524ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 8 Jun 2023 01:26:41 +0200 Subject: [PATCH] fix(napi): don't panic if symbol can't be found (#19397) This should return an error to the caller to make it easier to track what went wrong. Should help with debugging https://github.com/denoland/deno/issues/19389 --- ext/napi/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 22d86e4a9b..ada9aa13fb 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -647,12 +647,13 @@ where // SAFETY: we are going blind, calling the register function on the other side. let maybe_exports = unsafe { - let init = library + let Ok(init) = library .get:: napi_value>(b"napi_register_module_v1") - .expect("napi_register_module_v1 not found"); + ) -> napi_value>(b"napi_register_module_v1") else { + return Err(type_error(format!("Unable to find napi_register_module_v1 symbol in {}", path))); + }; init( env_ptr, std::mem::transmute::, napi_value>(exports.into()),