improve parsing error alert

This commit is contained in:
MihailRis
2024-07-24 17:11:43 +03:00
parent fe1ac69b57
commit 18d473b673
4 changed files with 42 additions and 28 deletions
+1 -6
View File
@@ -123,12 +123,7 @@ bool files::write_binary_json(const fs::path& filename, const dynamic::Map* obj,
std::shared_ptr<dynamic::Map> files::read_json(const fs::path& filename) {
std::string text = files::read_string(filename);
try {
return json::parse(filename.string(), text);;
} catch (const parsing_error& error) {
std::cerr << error.errorLog() << std::endl;
throw std::runtime_error("could not to parse "+filename.string());
}
return json::parse(filename.string(), text);
}
std::shared_ptr<dynamic::Map> files::read_binary_json(const fs::path& file) {
+1 -1
View File
@@ -29,7 +29,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidde
auto label = std::make_shared<Label>(text);
label->setMultiline(true);
label->setSize(glm::vec2(1, 80));
label->setSize(glm::vec2(1, 90));
panel->add(label);
panel->add(std::make_shared<Button>(
langs::get(L"Ok"), glm::vec4(10.f),
+9
View File
@@ -1,5 +1,6 @@
#include "EngineController.hpp"
#include "../coders/commons.hpp"
#include "../content/ContentLUT.hpp"
#include "../debug/Logger.hpp"
#include "../engine.hpp"
@@ -103,6 +104,10 @@ static bool loadWorldContent(Engine* engine, const fs::path& folder) {
util::str2wstr_utf8(error.what())
);
return false;
} catch (const parsing_error& error) {
engine->setScreen(std::make_shared<MenuScreen>(engine));
guiutil::alert(engine->getGUI(), util::str2wstr_utf8(error.errorLog()));
return false;
} catch (const std::runtime_error& error) {
engine->setScreen(std::make_shared<MenuScreen>(engine));
guiutil::alert(
@@ -204,6 +209,10 @@ void EngineController::createWorld(
L":\n"+util::str2wstr_utf8(error.what())
);
return;
} catch (const parsing_error& error) {
engine->setScreen(std::make_shared<MenuScreen>(engine));
guiutil::alert(engine->getGUI(), util::str2wstr_utf8(error.errorLog()));
return;
} catch (const std::runtime_error& error) {
engine->setScreen(std::make_shared<MenuScreen>(engine));
guiutil::alert(