diff --git a/module/Base/DynArg.hpp b/module/Base/DynArg.hpp index a6f325d3..acceb618 100644 --- a/module/Base/DynArg.hpp +++ b/module/Base/DynArg.hpp @@ -391,8 +391,12 @@ template < typename F, typename U, typename... Ts > SQInteger SqDynArgFwd(HSQUIR try { 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()); } diff --git a/module/Core/Command.cpp b/module/Core/Command.cpp index e65222a5..53ccf6b5 100644 --- a/module/Core/Command.cpp +++ b/module/Core/Command.cpp @@ -279,6 +279,11 @@ int32_t Controller::Run(const Guard & guard, const char * command) { 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) { // 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); } + 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) { // 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); } + 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) { // 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); } + 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) { // Tell the script callback to deal with the error diff --git a/module/Core/Command.hpp b/module/Core/Command.hpp index 180c3540..9df479da 100644 --- a/module/Core/Command.hpp +++ b/module/Core/Command.hpp @@ -390,6 +390,11 @@ protected: { 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) { // The debugger probably took care of reporting the details diff --git a/module/Core/Entity.cpp b/module/Core/Entity.cpp index bb9b9733..21b1bcf8 100644 --- a/module/Core/Entity.cpp +++ b/module/Core/Entity.cpp @@ -17,6 +17,11 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ #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) /* */ { /* */ LogErr("Squirrel exception caught " action); /* diff --git a/module/Core/Events.inc b/module/Core/Events.inc index 88587f1e..2f8fb45e 100644 --- a/module/Core/Events.inc +++ b/module/Core/Events.inc @@ -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 o = Var< LightObj >(SqVM(), -1).value; } + catch (const Poco::Exception & e) + { + STHROWF("{}", e.displayText()); // Re-package + } catch (const std::exception & e) { STHROWF("{}", e.what()); // Re-package diff --git a/module/Core/Routine.cpp b/module/Core/Routine.cpp index 347dd371..52285873 100644 --- a/module/Core/Routine.cpp +++ b/module/Core/Routine.cpp @@ -198,7 +198,7 @@ SQInteger Routine::Create(HSQUIRRELVM vm) } 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 HSQOBJECT obj; @@ -248,7 +248,7 @@ SQInteger Routine::Create(HSQUIRRELVM vm) // Clear extracted arguments inst.Clear(); // 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 diff --git a/module/Core/Signal.cpp b/module/Core/Signal.cpp index 7723bfa6..3f7a2d7a 100644 --- a/module/Core/Signal.cpp +++ b/module/Core/Signal.cpp @@ -1348,6 +1348,10 @@ SQInteger Signal::SqEmit(HSQUIRRELVM vm) res = signal->Emit(vm, top); } } + catch (const Poco::Exception& e) + { + return sq_throwerror(vm, e.displayText().c_str()); + } catch (const std::exception & e) { res = sq_throwerror(vm, e.what()); @@ -1388,6 +1392,10 @@ SQInteger Signal::SqQuery(HSQUIRRELVM vm) res = signal->Query(vm, top); } } + catch (const Poco::Exception& e) + { + return sq_throwerror(vm, e.displayText().c_str()); + } catch (const std::exception & e) { res = sq_throwerror(vm, e.what()); @@ -1418,6 +1426,10 @@ SQInteger Signal::SqConsume(HSQUIRRELVM vm) res = signal->Consume(vm, top); } } + catch (const Poco::Exception& e) + { + return sq_throwerror(vm, e.displayText().c_str()); + } catch (const std::exception & e) { res = sq_throwerror(vm, e.what()); @@ -1448,6 +1460,10 @@ SQInteger Signal::SqApprove(HSQUIRRELVM vm) res = signal->Approve(vm, top); } } + catch (const Poco::Exception& e) + { + return sq_throwerror(vm, e.displayText().c_str()); + } catch (const std::exception & e) { res = sq_throwerror(vm, e.what()); @@ -1478,6 +1494,10 @@ SQInteger Signal::SqRequest(HSQUIRRELVM vm) res = signal->Request(vm, top); } } + catch (const Poco::Exception& e) + { + return sq_throwerror(vm, e.displayText().c_str()); + } catch (const std::exception & e) { res = sq_throwerror(vm, e.what()); diff --git a/module/Main.cpp b/module/Main.cpp index 05b9a2fb..0d4e6cb7 100644 --- a/module/Main.cpp +++ b/module/Main.cpp @@ -69,6 +69,11 @@ void DoReload() // -------------------------------------------------------------------------------------------- #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) /* */ { /* */ LogErr("Squirrel exception caught (" #ev ") event"); /* @@ -982,6 +987,11 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback 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) { LogErr("Squirrel exception caught during initialization"); diff --git a/module/PocoLib/Crypto.cpp b/module/PocoLib/Crypto.cpp index 63e6ef01..ee47fe15 100644 --- a/module/PocoLib/Crypto.cpp +++ b/module/PocoLib/Crypto.cpp @@ -37,6 +37,10 @@ static SQInteger SqGetHash(HSQUIRRELVM vm) // Push the result on the stack 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) { 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 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) { 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 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) { 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 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) { 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 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) { 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 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) { 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 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) { return sq_throwerrorf(vm, _SC("Failed to compute checksum: %s"), e.what()); diff --git a/module/Sqrat/sqratGlobalMethods.h b/module/Sqrat/sqratGlobalMethods.h index 0534869b..cbd37e4e 100644 --- a/module/Sqrat/sqratGlobalMethods.h +++ b/module/Sqrat/sqratGlobalMethods.h @@ -122,6 +122,8 @@ template struct SqGlobal { #endif try { return SqGlobalProxy::template Run(vm, startIdx); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -148,6 +150,8 @@ template struct SqGlobal { #endif try { return SqGlobalProxy::template Run(vm, startIdx); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -174,6 +178,8 @@ template <> struct SqGlobal { #endif try { return SqGlobalProxy::Run(vm, startIdx); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { diff --git a/module/Sqrat/sqratMemberMethods.h b/module/Sqrat/sqratMemberMethods.h index 05cb4942..fe85e1da 100644 --- a/module/Sqrat/sqratMemberMethods.h +++ b/module/Sqrat/sqratMemberMethods.h @@ -152,6 +152,8 @@ template struct SqMember { #endif try { return SqMemberProxy:: template Run(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -171,6 +173,8 @@ template struct SqMember { #endif try { return SqMemberProxy::template RunC(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -197,6 +201,8 @@ template struct SqMember { #endif try { return SqMemberProxy::template Run(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -216,6 +222,8 @@ template struct SqMember { #endif try { return SqMemberProxy::template RunC(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -243,6 +251,8 @@ template struct SqMember { #endif try { return SqMemberProxy::template Run(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { @@ -262,6 +272,8 @@ template struct SqMember { #endif try { return SqMemberProxy::template RunC(vm); + } catch (const Poco::Exception& e) { + return sq_throwerror(vm, e.displayText().c_str()); } catch (const std::exception& e) { return sq_throwerror(vm, e.what()); } catch (...) { diff --git a/module/Sqrat/sqratUtil.h b/module/Sqrat/sqratUtil.h index 8bd381ae..a8a16539 100644 --- a/module/Sqrat/sqratUtil.h +++ b/module/Sqrat/sqratUtil.h @@ -37,6 +37,8 @@ #include #include +#include + namespace Sqrat { #if defined(__GNUC__)