Skip to content

Commit eef31a7

Browse files
committed
Fix failure to detect load failure
The error member might be set in a nested includes error handler and the `|=` might have read the old "true" value as the error is not further propagated. As a failing include should stop the script evaluation throw an exception propagating upwards. I.e. main: include(foo) foo: include(bar) bar: error out foo stores error from including bar Previously foo then continued and hence main also did. Not foo aborts too causing main to also abort.
1 parent 17a3c58 commit eef31a7

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

libs/libGamedata/lua/GameDataLoader.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
namespace bfs = boost::filesystem;
2121

2222
GameDataLoader::GameDataLoader(WorldDescription& worldDesc, const boost::filesystem::path& basePath)
23-
: worldDesc_(worldDesc), basePath_(basePath.lexically_normal().make_preferred()), curIncludeDepth_(0),
24-
errorInIncludeFile_(false)
23+
: worldDesc_(worldDesc), basePath_(basePath.lexically_normal().make_preferred()), curIncludeDepth_(0)
2524
{
2625
Register(lua);
2726

@@ -39,17 +38,14 @@ bool GameDataLoader::Load()
3938
{
4039
curFile_ = basePath_ / "default.lua";
4140
curIncludeDepth_ = 0;
42-
errorInIncludeFile_ = false;
4341
try
4442
{
45-
if(!loadScript(curFile_))
46-
return false;
43+
return loadScript(curFile_);
4744
} catch(const std::exception& e)
4845
{
4946
LOG.write("Failed to load game data!\nReason: %1%\nCurrent file being processed: %2%\n") % e.what() % curFile_;
5047
return false;
5148
}
52-
return !errorInIncludeFile_;
5349
}
5450

5551
void GameDataLoader::Register(kaguya::State& state)
@@ -95,7 +91,8 @@ void GameDataLoader::Include(const std::string& filepath)
9591
const auto oldCurFile = curFile_;
9692
curFile_ = absFilePath;
9793
++curIncludeDepth_;
98-
errorInIncludeFile_ |= !loadScript(absFilePath);
94+
if(!loadScript(absFilePath))
95+
throw std::runtime_error(helpers::format("Include file '%1%' cannot be included", filepath));
9996
curFile_ = oldCurFile;
10097
RTTR_Assert(curIncludeDepth_ > 0);
10198
--curIncludeDepth_;

libs/libGamedata/lua/GameDataLoader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class GameDataLoader : public LuaInterfaceBase
3333
WorldDescription& worldDesc_;
3434
boost::filesystem::path basePath_, curFile_;
3535
int curIncludeDepth_;
36-
bool errorInIncludeFile_;
3736
};
3837

3938
void loadGameData(WorldDescription& worldDesc);

0 commit comments

Comments
 (0)