Skip to content

Commit

Permalink
Better JS exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed May 30, 2024
1 parent 076636c commit 9995d0f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Bannerlord::LauncherManager
delete data;
return info.Env().Null();
}
catch (const std::exception &e)
catch (const Napi::Error &e)

Check warning on line 170 in src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp

View workflow job for this annotation

GitHub Actions / Publish on NPM and GPR

'e': unreferenced local variable

Check warning on line 170 in src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.LauncherManager.hpp

View workflow job for this annotation

GitHub Actions / Publish on NPM and GPR

'e': unreferenced local variable
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return info.Env().Null();
Expand All @@ -187,10 +187,10 @@ namespace Bannerlord::LauncherManager
manager->FSetGameParameters({executable, gameParameters});
return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_json *getLoadOrder(void *p_owner) noexcept
Expand All @@ -203,10 +203,10 @@ namespace Bannerlord::LauncherManager
const auto result = manager->FGetLoadOrder({}).As<Object>();
return Create(return_value_json{nullptr, Copy(JSONStringify(env, result).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_void *setLoadOrder(void *p_owner, char16_t *p_load_order) noexcept
Expand All @@ -220,10 +220,10 @@ namespace Bannerlord::LauncherManager
manager->FSetLoadOrder({loadOrder});
return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_void *sendNotification(void *p_owner, char16_t *p_id, char16_t *p_type, char16_t *p_message, uint32_t displayMs) noexcept
Expand All @@ -240,10 +240,10 @@ namespace Bannerlord::LauncherManager
manager->FSendNotification({id, type, message, displayMs_});
return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
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
Expand Down Expand Up @@ -278,10 +278,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_string *getInstallPath(void *p_owner) noexcept
Expand All @@ -294,10 +294,10 @@ namespace Bannerlord::LauncherManager
const auto result = manager->FGetInstallPath({}).As<String>();
return Create(return_value_string{nullptr, Copy(result.Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_string{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_string{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_data *readFileContent(void *p_owner, char16_t *p_file_path, int32_t p_offset, int32_t p_length) noexcept
Expand Down Expand Up @@ -326,10 +326,10 @@ namespace Bannerlord::LauncherManager
auto buffer = result.As<Buffer<uint8_t>>();
return Create(return_value_data{nullptr, Copy(buffer.Data(), buffer.ByteLength()), static_cast<int>(buffer.ByteLength())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_data{Copy(conv.from_bytes(e.what())), nullptr, 0});
return Create(return_value_data{Copy(conv.from_bytes(e.Message())), nullptr, 0});
}
}
static return_value_void *writeFileContent(void *p_owner, char16_t *p_file_path, uint8_t *p_data, int32_t length) noexcept
Expand All @@ -349,10 +349,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_json *readDirectoryFileList(void *p_owner, char16_t *p_directory_path) noexcept
Expand All @@ -371,10 +371,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_json *readDirectoryList(void *p_owner, char16_t *p_directory_path) noexcept
Expand All @@ -393,10 +393,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_json *getAllModuleViewModels(void *p_owner) noexcept
Expand All @@ -414,10 +414,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_json *getModuleViewModels(void *p_owner) noexcept
Expand All @@ -435,10 +435,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_void *setModuleViewModels(void *p_owner, char16_t *p_module_view_models) noexcept
Expand All @@ -457,10 +457,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_json *getOptions(void *p_owner) noexcept
Expand All @@ -478,10 +478,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}
static return_value_json *getState(void *p_owner) noexcept
Expand All @@ -499,10 +499,10 @@ namespace Bannerlord::LauncherManager

return Create(return_value_json{nullptr, Copy(JSONStringify(env, result.As<Object>()).Utf16Value())});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_json{Copy(conv.from_bytes(e.what())), nullptr});
return Create(return_value_json{Copy(conv.from_bytes(e.Message())), nullptr});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ namespace Bannerlord::ModuleManager

return Create(return_value_bool{nullptr, data->FIsSelected({moduleId}).As<Boolean>()});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_bool{Copy(conv.from_bytes(e.what())), false});
return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false});
}
}

Expand All @@ -54,10 +54,10 @@ namespace Bannerlord::ModuleManager

return Create(return_value_bool{nullptr, data->FGetSelected({moduleId}).As<Boolean>()});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_bool{Copy(conv.from_bytes(e.what())), false});
return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false});
}
}
static return_value_void *setSelected(param_ptr *p_owner, param_string *p_module_id, param_bool value_raw) noexcept
Expand All @@ -73,10 +73,10 @@ namespace Bannerlord::ModuleManager
data->FSetSelected({moduleId, value});
return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}
static return_value_bool *getDisabled(param_ptr *p_owner, param_string *p_module_id) noexcept
Expand All @@ -90,10 +90,10 @@ namespace Bannerlord::ModuleManager

return Create(return_value_bool{nullptr, data->FGetDisabled({moduleId}).As<Boolean>()});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_bool{Copy(conv.from_bytes(e.what())), false});
return Create(return_value_bool{Copy(conv.from_bytes(e.Message())), false});
}
}
static return_value_void *setDisabled(param_ptr *p_owner, param_string *p_module_id, param_bool value_raw) noexcept
Expand All @@ -109,10 +109,10 @@ namespace Bannerlord::ModuleManager
data->FSetDisabled({moduleId, value});
return Create(return_value_void{nullptr});
}
catch (const std::exception &e)
catch (const Napi::Error &e)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
return Create(return_value_void{Copy(conv.from_bytes(e.what()))});
return Create(return_value_void{Copy(conv.from_bytes(e.Message()))});
}
}

Expand Down

0 comments on commit 9995d0f

Please sign in to comment.