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

Prevent silent failure uppon loading scripts that don't exist.

This commit is contained in:
Sandu Liviu Catalin 2020-04-30 22:28:01 +03:00
parent 88ef01e5e8
commit 1edc1930a3
3 changed files with 22 additions and 22 deletions

View File

@ -27,7 +27,7 @@ public:
{
if (!mFile)
{
throw std::runtime_error(ToStrF("Unable to open script source (%s)", path));
STHROWF("Unable to open script source (%s)", path);
}
}
@ -151,9 +151,9 @@ void ScriptSrc::Process()
}
// ------------------------------------------------------------------------------------------------
ScriptSrc::ScriptSrc(HSQUIRRELVM vm, String && path, bool delay, bool info)
ScriptSrc::ScriptSrc(HSQUIRRELVM vm, const String & path, bool delay, bool info)
: mExec(vm)
, mPath(std::move(path))
, mPath(path)
, mData()
, mLine()
, mInfo(info)

View File

@ -39,16 +39,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
ScriptSrc(HSQUIRRELVM vm, const String & path, bool delay = false, bool info = false)
: ScriptSrc(vm, String(path), delay, info)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
ScriptSrc(HSQUIRRELVM vm, String && path, bool delay = false, bool info = false);
ScriptSrc(HSQUIRRELVM vm, const String & path, bool delay = false, bool info = false);
/* --------------------------------------------------------------------------------------------
* Copy constructor.

View File

@ -675,23 +675,23 @@ bool Core::LoadScript(CSStr filepath, bool delay)
else if (m_Executed)
{
// Create a new script container and insert it into the script pool
m_Scripts.emplace_back(m_VM, std::move(path), delay, m_Debugging);
m_Scripts.emplace_back(m_VM, path, delay, m_Debugging);
// Attempt to load and compile the script file
try
{
m_Scripts.back().mExec.CompileFile(m_Scripts.back().mPath);
m_Scripts.back().mExec.CompileFile(path);
}
catch (const Sqrat::Exception & e)
{
LogFtl("Unable to compile: %s", m_Scripts.back().mPath.c_str());
LogFtl("Unable to compile: %s", path.c_str());
// Remove the script container since it's invalid
m_Scripts.pop_back();
// Failed to compile properly
return false;
}
// At this point the script should be completely loaded
cLogDbg(m_Verbosity >= 3, "Compiled script: %s", m_Scripts.back().mPath.c_str());
cLogDbg(m_Verbosity >= 3, "Compiled script: %s", path.c_str());
// Attempt to execute the compiled script code
try
@ -700,22 +700,31 @@ bool Core::LoadScript(CSStr filepath, bool delay)
}
catch (const Sqrat::Exception & e)
{
LogFtl("Unable to execute: %s", m_Scripts.back().mPath.c_str());
LogFtl("Unable to execute: %s", path.c_str());
// Remove the script container since it's invalid
m_Scripts.pop_back();
// Failed to execute properly
return false;
}
// At this point the script should be completely loaded
cLogScs(m_Verbosity >= 2, "Executed script: %s", m_Scripts.back().mPath.c_str());
cLogScs(m_Verbosity >= 2, "Executed script: %s", path.c_str());
}
// We don't compile the scripts yet. We just store their path and prepare the objects
else
{
cLogDbg(m_Verbosity >= 2, "Pending %s script: %s", (delay ? "deferred" : "immediate"), path.c_str());
// Create a new script container and insert it into the pending script pool
m_PendingScripts.emplace_back(m_VM, std::move(path), delay, m_Debugging);
// Attempt to queue the script
try
{
// Create a new script container and insert it into the pending script pool
m_PendingScripts.emplace_back(m_VM, path, delay, m_Debugging);
}
catch (const Sqrat::Exception & e)
{
LogFtl("Unable to queue: %s", e.what());
// Failed to queue script
return false;
}
}
// At this point the script exists in one of the pools