mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-25 13:30:43 +00:00
fix error handling from SetErrorMessageFromResult
This commit is contained in:
2 files changed
+16
-4
No files matched your search
@@ -34,6 +34,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sol/forward.hpp>
|
||||||
#include <sol/protected_function_result.hpp>
|
#include <sol/protected_function_result.hpp>
|
||||||
#include <toml.hpp>
|
#include <toml.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -86,8 +87,14 @@ struct TLuaResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void SetErrorMessageFromResult(sol::protected_function_result& Res) {
|
void SetErrorMessageFromResult(sol::protected_function_result& Res) {
|
||||||
auto error = Res.get<std::optional<std::string>>();
|
if (Res.valid()) {
|
||||||
ErrorMessage = error ? *error : "(unknown error; error object is not a string value)";
|
beammp_lua_errorf("Error was not an error");
|
||||||
|
}
|
||||||
|
if (Res.get_type() == sol::type::string) {
|
||||||
|
ErrorMessage = Res.get<sol::error>().what();
|
||||||
|
} else {
|
||||||
|
ErrorMessage = "(unknown error; error object is not inspectable)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkAsReady();
|
void MarkAsReady();
|
||||||
|
|||||||
+7
-2
@@ -550,8 +550,13 @@ sol::table TLuaEngine::StateThreadData::Lua_TriggerLocalEvent(const std::string&
|
|||||||
Result.set(i, FnRet);
|
Result.set(i, FnRet);
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
auto ErrStr = FnRet.get<std::optional<std::string>>();
|
std::string ErrStr;
|
||||||
beammp_lua_error(std::string("TriggerLocalEvent: ") + (ErrStr ? *ErrStr : "(unknown error; error object is not a string)"));
|
if (FnRet.get_type() == sol::type::string) {
|
||||||
|
ErrStr = FnRet.get<sol::error>().what();
|
||||||
|
} else {
|
||||||
|
ErrStr = "(unknown error; error object is not inspectable)";
|
||||||
|
}
|
||||||
|
beammp_lua_errorf("TriggerLocalEvent: {}", ErrStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user