Skip to content

Commit

Permalink
Merge pull request #997 from psiberx/master
Browse files Browse the repository at this point in the history
Log all errors occurring in require()
  • Loading branch information
WSSDude authored Jan 25, 2025
2 parents 72ed761 + 14691ef commit 42c3c8d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/scripting/LuaSandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void LuaSandbox::Initialize()
existingLogger->warn("CET launched with MO2.");
}
}

// copy whitelisted things from global table
for (const auto* cKey : s_cVMGlobalObjectsWhitelist)
{
Expand Down Expand Up @@ -448,6 +448,9 @@ void LuaSandbox::InitializeIOForSandbox(Sandbox& aSandbox, const sol::state& acp
{
current_path(previousCurrentPath);

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

return res;
}

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

auto logger = cSBEnv["__logger"].get<std::shared_ptr<spdlog::logger>>();
logger->error("Error: Cannot load module '{}': {}", acPath, e.what());

return std::make_tuple(sol::nil, make_object(stateView, e.what()));
}

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

current_path(previousCurrentPath);

sol::error err = result;
auto logger = cSBEnv["__logger"].get<std::shared_ptr<spdlog::logger>>();
logger->error("Error: Cannot load module '{}': {}", acPath, err.what());

current_path(previousCurrentPath);

return std::make_tuple(sol::nil, make_object(stateView, err.what()));
}

Expand Down

0 comments on commit 42c3c8d

Please sign in to comment.