From f00daf171b9c35554dbe96fdfd04b210c3486bed Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 16 Nov 2023 09:32:32 +0100 Subject: [PATCH] fix: Crash when loading invalid theme file --- lib/libimhex/source/api/theme_manager.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/libimhex/source/api/theme_manager.cpp b/lib/libimhex/source/api/theme_manager.cpp index d36e017ef..09fb4894d 100644 --- a/lib/libimhex/source/api/theme_manager.cpp +++ b/lib/libimhex/source/api/theme_manager.cpp @@ -29,11 +29,16 @@ namespace hex { } void ThemeManager::addTheme(const std::string &content) { - auto theme = nlohmann::json::parse(content); - if (theme.contains("name") && theme.contains("colors")) { - s_themes[theme["name"].get()] = theme; - } else { - hex::log::error("Invalid theme file"); + try { + auto theme = nlohmann::json::parse(content); + + if (theme.contains("name") && theme.contains("colors")) { + s_themes[theme["name"].get()] = theme; + } else { + hex::log::error("Invalid theme file"); + } + } catch (const nlohmann::json::parse_error &e) { + hex::log::error("Invalid theme file: {}", e.what()); } }