From 182ca15bbe2751ae6c8d26f4acf8778f5576dbe4 Mon Sep 17 00:00:00 2001 From: Oleksandr Nemesh Date: Fri, 29 Mar 2024 17:00:37 +0200 Subject: [PATCH] fix corrupted config loading AGAIN --- src/shared/config.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/shared/config.cpp b/src/shared/config.cpp index 992fedd..cf44a1f 100644 --- a/src/shared/config.cpp +++ b/src/shared/config.cpp @@ -39,13 +39,14 @@ namespace openhack::config { return; } - try { - file >> storage; + storage = nlohmann::json::parse(file, nullptr, false); + if (storage.is_discarded()) { file.close(); - } catch (const nlohmann::json::parse_error &e) { - file.close(); - L_WARN("Failed to parse config file: {}", e.what()); + L_WARN("Failed to parse config file, creating a new one"); + storage = nlohmann::json(); save(); + } else { + file.close(); } }