1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-16 07:07:13 +02: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

@ -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

View File

@ -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

View File

@ -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); /*

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
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

View File

@ -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

View File

@ -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());