1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Handle Poco exceptions explicitly.

This commit is contained in:
Sandu Liviu Catalin 2021-02-20 21:22:12 +02:00
parent 505650837e
commit 1f2b75ed26
12 changed files with 119 additions and 3 deletions

View File

@ -391,8 +391,12 @@ template < typename F, typename U, typename... Ts > SQInteger SqDynArgFwd(HSQUIR
try try
{ {
return SqDynArgImpl< U, Ts... >::Try(fn, vm); return SqDynArgImpl< U, Ts... >::Try(fn, vm);
}
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
} }
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} }

View File

@ -279,6 +279,11 @@ int32_t Controller::Run(const Guard & guard, const char * command)
{ {
return Exec(ctx); return Exec(ctx);
} }
catch (const Poco::Exception& e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_EXECUTION_FAILED, _SC("Exceptions occurred during execution"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
// Tell the script callback to deal with the error // Tell the script callback to deal with the error
@ -425,6 +430,11 @@ int32_t Controller::Exec(Context & ctx)
{ {
ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result); ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result);
} }
catch (const Poco::Exception& e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
// Tell the script callback to deal with the error // Tell the script callback to deal with the error
@ -447,6 +457,11 @@ int32_t Controller::Exec(Context & ctx)
{ {
ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result); ctx.mInstance->m_OnFail.Execute(ctx.mInvoker, result);
} }
catch (const Poco::Exception& e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_UNRESOLVED_FAILURE, _SC("Unable to resolve command failure"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
// Tell the script callback to deal with the error // Tell the script callback to deal with the error
@ -462,6 +477,11 @@ int32_t Controller::Exec(Context & ctx)
{ {
ctx.mInstance->m_OnPost.Execute(ctx.mInvoker, result); ctx.mInstance->m_OnPost.Execute(ctx.mInvoker, result);
} }
catch (const Poco::Exception& e)
{
// Tell the script callback to deal with the error
SqError(CMDERR_POST_PROCESSING_FAILED, _SC("Unable to complete command post processing"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
// Tell the script callback to deal with the error // Tell the script callback to deal with the error

View File

@ -390,6 +390,11 @@ protected:
{ {
m_OnFail.Execute(type, msg, data); m_OnFail.Execute(type, msg, data);
} }
catch (const Poco::Exception& e)
{
// The debugger probably took care of reporting the details
LogErr("Command error callback failed [%s]", e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
// The debugger probably took care of reporting the details // The debugger probably took care of reporting the details

View File

@ -17,6 +17,11 @@ namespace SqMod {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(action) /* #define SQMOD_CATCH_EVENT_EXCEPTION(action) /*
*/ catch (const Poco::Exception & e) /*
*/ { /*
*/ LogErr("Program exception caught " action); /*
*/ Logger::Get().DebugF(SqVM(), "%s", e.displayText().c_str()); /*
*/ } /*
*/ catch (const Sqrat::Exception & e) /* */ catch (const Sqrat::Exception & e) /*
*/ { /* */ { /*
*/ LogErr("Squirrel exception caught " action); /* */ LogErr("Squirrel exception caught " action); /*

View File

@ -1848,6 +1848,10 @@ void Core::EmitClientScriptData(int32_t player_id, const uint8_t * data, size_t
// Get the object from the stack and store it // Get the object from the stack and store it
o = Var< LightObj >(SqVM(), -1).value; o = Var< LightObj >(SqVM(), -1).value;
} }
catch (const Poco::Exception & e)
{
STHROWF("{}", e.displayText()); // Re-package
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
STHROWF("{}", e.what()); // Re-package STHROWF("{}", e.what()); // Re-package

View File

@ -198,7 +198,7 @@ SQInteger Routine::Create(HSQUIRRELVM vm)
} }
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerror(vm, "Unable to create the routine instance"); return sq_throwerrorf(vm, "Unable to create the routine instance: %s", e.what());
} }
// Prepare an object for the routine // Prepare an object for the routine
HSQOBJECT obj; HSQOBJECT obj;
@ -248,7 +248,7 @@ SQInteger Routine::Create(HSQUIRRELVM vm)
// Clear extracted arguments // Clear extracted arguments
inst.Clear(); inst.Clear();
// Now it's safe to throw the error // Now it's safe to throw the error
return sq_throwerror(vm, "Unable to create the routine instance"); return sq_throwerrorf(vm, "Unable to create the routine instance: %s", e.what());
} }
// Alright, at this point we can initialize the slot // Alright, at this point we can initialize the slot

View File

@ -1348,6 +1348,10 @@ SQInteger Signal::SqEmit(HSQUIRRELVM vm)
res = signal->Emit(vm, top); res = signal->Emit(vm, top);
} }
} }
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
res = sq_throwerror(vm, e.what()); res = sq_throwerror(vm, e.what());
@ -1388,6 +1392,10 @@ SQInteger Signal::SqQuery(HSQUIRRELVM vm)
res = signal->Query(vm, top); res = signal->Query(vm, top);
} }
} }
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
res = sq_throwerror(vm, e.what()); res = sq_throwerror(vm, e.what());
@ -1418,6 +1426,10 @@ SQInteger Signal::SqConsume(HSQUIRRELVM vm)
res = signal->Consume(vm, top); res = signal->Consume(vm, top);
} }
} }
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
res = sq_throwerror(vm, e.what()); res = sq_throwerror(vm, e.what());
@ -1448,6 +1460,10 @@ SQInteger Signal::SqApprove(HSQUIRRELVM vm)
res = signal->Approve(vm, top); res = signal->Approve(vm, top);
} }
} }
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
res = sq_throwerror(vm, e.what()); res = sq_throwerror(vm, e.what());
@ -1478,6 +1494,10 @@ SQInteger Signal::SqRequest(HSQUIRRELVM vm)
res = signal->Request(vm, top); res = signal->Request(vm, top);
} }
} }
catch (const Poco::Exception& e)
{
return sq_throwerror(vm, e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
res = sq_throwerror(vm, e.what()); res = sq_throwerror(vm, e.what());

View File

@ -69,6 +69,11 @@ void DoReload()
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(ev) /* #define SQMOD_CATCH_EVENT_EXCEPTION(ev) /*
*/ catch (const Poco::Exception & e) /*
*/ { /*
*/ LogErr("Squirrel exception caught (" #ev ") event"); /*
*/ LogSInf("Message: %s", e.displayText().c_str()); /*
*/ } /*
*/ catch (const std::exception & e) /* */ catch (const std::exception & e) /*
*/ { /* */ { /*
*/ LogErr("Squirrel exception caught (" #ev ") event"); /* */ LogErr("Squirrel exception caught (" #ev ") event"); /*
@ -982,6 +987,11 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
return SQMOD_FAILURE; return SQMOD_FAILURE;
} }
} }
catch (const Poco::Exception & e)
{
LogErr("Program exception caught during initialization");
LogSInf("Message: %s", e.displayText().c_str());
}
catch (const Sqrat::Exception & e) catch (const Sqrat::Exception & e)
{ {
LogErr("Squirrel exception caught during initialization"); LogErr("Squirrel exception caught during initialization");

View File

@ -37,6 +37,10 @@ static SQInteger SqGetHash(HSQUIRRELVM vm)
// Push the result on the stack // Push the result on the stack
Var< String >::push(vm, hex); Var< String >::push(vm, hex);
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to hash: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to hash: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to hash: %s"), e.what());
@ -69,6 +73,10 @@ static SQInteger SqEncodeBase32(HSQUIRRELVM vm)
// Push the resulted string on the stack // Push the resulted string on the stack
Var< String >::push(vm, out.str()); Var< String >::push(vm, out.str());
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.what());
@ -102,6 +110,10 @@ static SQInteger SqDecodeBase32(HSQUIRRELVM vm)
// Push the resulted string on the stack // Push the resulted string on the stack
Var< String >::push(vm, out); Var< String >::push(vm, out);
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.what());
@ -134,6 +146,10 @@ static SQInteger SqEncodeBase64(HSQUIRRELVM vm)
// Push the resulted string on the stack // Push the resulted string on the stack
Var< String >::push(vm, out.str()); Var< String >::push(vm, out.str());
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to encode: %s"), e.what());
@ -167,6 +183,10 @@ static SQInteger SqDecodeBase64(HSQUIRRELVM vm)
// Push the resulted string on the stack // Push the resulted string on the stack
Var< String >::push(vm, out); Var< String >::push(vm, out);
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to decode: %s"), e.what());
@ -195,6 +215,10 @@ static SQInteger SqGetCRC32(HSQUIRRELVM vm)
// Push the result on the stack // Push the result on the stack
sq_pushinteger(vm, static_cast< SQInteger >(c.checksum())); sq_pushinteger(vm, static_cast< SQInteger >(c.checksum()));
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.what());
@ -223,6 +247,10 @@ static SQInteger SqGetADLER32(HSQUIRRELVM vm)
// Push the result on the stack // Push the result on the stack
sq_pushinteger(vm, static_cast< SQInteger >(c.checksum())); sq_pushinteger(vm, static_cast< SQInteger >(c.checksum()));
} }
catch (const Poco::Exception& e)
{
return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.displayText().c_str());
}
catch (const std::exception & e) catch (const std::exception & e)
{ {
return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.what()); return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.what());

View File

@ -122,6 +122,8 @@ template <class R> struct SqGlobal {
#endif #endif
try { try {
return SqGlobalProxy<R>::template Run<A...>(vm, startIdx); return SqGlobalProxy<R>::template Run<A...>(vm, startIdx);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -148,6 +150,8 @@ template <class R> struct SqGlobal<R&> {
#endif #endif
try { try {
return SqGlobalProxy<R&>::template Run<A...>(vm, startIdx); return SqGlobalProxy<R&>::template Run<A...>(vm, startIdx);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -174,6 +178,8 @@ template <> struct SqGlobal<void> {
#endif #endif
try { try {
return SqGlobalProxy<void>::Run<A...>(vm, startIdx); return SqGlobalProxy<void>::Run<A...>(vm, startIdx);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {

View File

@ -152,6 +152,8 @@ template <class C,class R> struct SqMember {
#endif #endif
try { try {
return SqMemberProxy<C, R>:: template Run<A...>(vm); return SqMemberProxy<C, R>:: template Run<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -171,6 +173,8 @@ template <class C,class R> struct SqMember {
#endif #endif
try { try {
return SqMemberProxy<C,R>::template RunC<A...>(vm); return SqMemberProxy<C,R>::template RunC<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -197,6 +201,8 @@ template <class C, class R> struct SqMember<C,R&> {
#endif #endif
try { try {
return SqMemberProxy<C,R&>::template Run<A...>(vm); return SqMemberProxy<C,R&>::template Run<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -216,6 +222,8 @@ template <class C, class R> struct SqMember<C,R&> {
#endif #endif
try { try {
return SqMemberProxy<C,R&>::template RunC<A...>(vm); return SqMemberProxy<C,R&>::template RunC<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -243,6 +251,8 @@ template <class C> struct SqMember<C, void> {
#endif #endif
try { try {
return SqMemberProxy<C, void>::template Run<A...>(vm); return SqMemberProxy<C, void>::template Run<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {
@ -262,6 +272,8 @@ template <class C> struct SqMember<C, void> {
#endif #endif
try { try {
return SqMemberProxy<C,void>::template RunC<A...>(vm); return SqMemberProxy<C,void>::template RunC<A...>(vm);
} catch (const Poco::Exception& e) {
return sq_throwerror(vm, e.displayText().c_str());
} catch (const std::exception& e) { } catch (const std::exception& e) {
return sq_throwerror(vm, e.what()); return sq_throwerror(vm, e.what());
} catch (...) { } catch (...) {

View File

@ -37,6 +37,8 @@
#include <exception> #include <exception>
#include <unordered_map> #include <unordered_map>
#include <Poco/Exception.h>
namespace Sqrat { namespace Sqrat {
#if defined(__GNUC__) #if defined(__GNUC__)