diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp index 698899c..7016d72 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp @@ -169,7 +169,6 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; return info.Env().Null(); } } @@ -189,9 +188,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - const auto stack = e.Value().Get("stack").As(); - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(stack.Utf16Value())}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_json *getLoadOrder(void *p_owner) noexcept @@ -206,8 +203,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_void *setLoadOrder(void *p_owner, char16_t *p_load_order) noexcept @@ -223,8 +219,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_void *sendNotification(void *p_owner, char16_t *p_id, char16_t *p_type, char16_t *p_message, uint32_t displayMs) noexcept @@ -243,8 +238,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_void *sendDialog(void *p_owner, char16_t *p_type, char16_t *p_title, char16_t *p_message, char16_t *p_filters, void *p_callback_ptr, void(__cdecl *p_callback)(void *, char16_t *)) noexcept @@ -281,8 +275,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_string *getInstallPath(void *p_owner) noexcept @@ -297,8 +290,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_string{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_string{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_data *readFileContent(void *p_owner, char16_t *p_file_path, int32_t p_offset, int32_t p_length) noexcept @@ -329,8 +321,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_data{Copy(conv.from_bytes(e.Message())), nullptr, 0}); + return Create(return_value_data{Copy(GetErrorMessage(e)), nullptr, 0}); } } static return_value_void *writeFileContent(void *p_owner, char16_t *p_file_path, uint8_t *p_data, int32_t length) noexcept @@ -352,8 +343,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_json *readDirectoryFileList(void *p_owner, char16_t *p_directory_path) noexcept @@ -374,8 +364,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_json *readDirectoryList(void *p_owner, char16_t *p_directory_path) noexcept @@ -396,8 +385,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_json *getAllModuleViewModels(void *p_owner) noexcept @@ -417,8 +405,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_json *getModuleViewModels(void *p_owner) noexcept @@ -438,8 +425,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_void *setModuleViewModels(void *p_owner, char16_t *p_module_view_models) noexcept @@ -460,8 +446,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_json *getOptions(void *p_owner) noexcept @@ -481,8 +466,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } static return_value_json *getState(void *p_owner) noexcept @@ -502,8 +486,7 @@ namespace Bannerlord::LauncherManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr}); + return Create(return_value_json{Copy(GetErrorMessage(e)), nullptr}); } } diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.ModuleManager.hpp b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.ModuleManager.hpp index 88a4d92..cf46b7e 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.ModuleManager.hpp +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.ModuleManager.hpp @@ -30,8 +30,7 @@ namespace Bannerlord::ModuleManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false}); + return Create(return_value_bool{Copy(GetErrorMessage(e)), false}); } } @@ -56,8 +55,7 @@ namespace Bannerlord::ModuleManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false}); + return Create(return_value_bool{Copy(GetErrorMessage(e)), false}); } } static return_value_void *setSelected(param_ptr *p_owner, param_string *p_module_id, param_bool value_raw) noexcept @@ -75,8 +73,7 @@ namespace Bannerlord::ModuleManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } static return_value_bool *getDisabled(param_ptr *p_owner, param_string *p_module_id) noexcept @@ -92,8 +89,7 @@ namespace Bannerlord::ModuleManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false}); + return Create(return_value_bool{Copy(GetErrorMessage(e)), false}); } } static return_value_void *setDisabled(param_ptr *p_owner, param_string *p_module_id, param_bool value_raw) noexcept @@ -111,8 +107,7 @@ namespace Bannerlord::ModuleManager } catch (const Napi::Error &e) { - std::wstring_convert, char16_t> conv; - return Create(return_value_void{Copy(conv.from_bytes(e.Message()))}); + return Create(return_value_void{Copy(GetErrorMessage(e))}); } } diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/utils.hpp b/src/Bannerlord.LauncherManager.Native.TypeScript/src/utils.hpp index 2dc7204..c8fead0 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/utils.hpp +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/utils.hpp @@ -114,6 +114,19 @@ namespace Utils return dst; } + std::u16string GetErrorMessage(const Napi::Error e) + { + const auto errorValue = e.Value(); + if (errorValue.Has("stack")) + { + const auto stack = e.Value().Get("stack").As(); + return stack.Utf16Value(); + } + + std::wstring_convert, char16_t> conv; + return conv.from_bytes(e.Message()); + } + void ConsoleLog(const Env env, const String message) { const auto consoleObject = env.Global().Get("console").As();