Skip to content

Commit 42c3c8d

Browse files
authored
Merge pull request #997 from psiberx/master
Log all errors occurring in require()
2 parents 72ed761 + 14691ef commit 42c3c8d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/scripting/LuaSandbox.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void LuaSandbox::Initialize()
137137
existingLogger->warn("CET launched with MO2.");
138138
}
139139
}
140-
140+
141141
// copy whitelisted things from global table
142142
for (const auto* cKey : s_cVMGlobalObjectsWhitelist)
143143
{
@@ -448,6 +448,9 @@ void LuaSandbox::InitializeIOForSandbox(Sandbox& aSandbox, const sol::state& acp
448448
{
449449
current_path(previousCurrentPath);
450450

451+
auto logger = cSBEnv["__logger"].get<std::shared_ptr<spdlog::logger>>();
452+
logger->error("Error: Cannot load module '{}': {}", acPath, std::get<1>(res).as<std::string>());
453+
451454
return res;
452455
}
453456

@@ -464,6 +467,9 @@ void LuaSandbox::InitializeIOForSandbox(Sandbox& aSandbox, const sol::state& acp
464467
{
465468
current_path(previousCurrentPath);
466469

470+
auto logger = cSBEnv["__logger"].get<std::shared_ptr<spdlog::logger>>();
471+
logger->error("Error: Cannot load module '{}': {}", acPath, e.what());
472+
467473
return std::make_tuple(sol::nil, make_object(stateView, e.what()));
468474
}
469475

@@ -477,12 +483,12 @@ void LuaSandbox::InitializeIOForSandbox(Sandbox& aSandbox, const sol::state& acp
477483
return std::make_tuple(resultObj, sol::nil);
478484
}
479485

486+
current_path(previousCurrentPath);
487+
480488
sol::error err = result;
481489
auto logger = cSBEnv["__logger"].get<std::shared_ptr<spdlog::logger>>();
482490
logger->error("Error: Cannot load module '{}': {}", acPath, err.what());
483491

484-
current_path(previousCurrentPath);
485-
486492
return std::make_tuple(sol::nil, make_object(stateView, err.what()));
487493
}
488494

0 commit comments

Comments
 (0)