Report errors in Observe and Override handlers
@@ -49,9 +49,18 @@ bool FunctionOverride::HookRunPureScriptFunction(RED4ext::CClassFunction* apFunc
for (const auto& call : calls)
{
const auto result = call->ScriptFunction(as_args(args), call->Environment);
+
+ if (!result.valid())
+ {
+ auto logger = call->Environment["__logger"].get<std::shared_ptr<spdlog::logger>>();
+ logger->error(result.get<sol::error>().what());
+
+ continue;
+ }
+
if (!call->Forward)
{
- if (result.valid() && ret.value && ret.type)
+ if (ret.value && ret.type)
Scripting::ToRED(result.get<sol::object>(), &ret);
return true;
@@ -212,6 +221,16 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
for (const auto& call : calls)
{
const auto result = call->ScriptFunction(as_args(args), call->Environment);
+
+ if (!result.valid())
+ {
+ auto logger = call->Environment["__logger"].get<std::shared_ptr<spdlog::logger>>();
+ logger->error(result.get<sol::error>().what());
+
+ continue;
+ }
+
+
if (!call->Forward)
{
if (apFunction->returnType)
@@ -220,7 +239,7 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
redResult.type = apFunction->returnType->type;
redResult.value = apOut;
- if (result.valid() && apOut)
+ if (apOut)
Scripting::ToRED(result.get<sol::object>(), &redResult);
}
