From 3c9e4c7c1874bee803ad8c241fff83fd5588cda8 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 5 Aug 2023 23:15:48 +1000 Subject: Fix crash with invalid meusum data (#789) try catch crash --- .../miscfeatures/inventory/MuseumTooltipManager.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/io') diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumTooltipManager.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumTooltipManager.kt index 3a7c69be..675708e9 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumTooltipManager.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumTooltipManager.kt @@ -51,11 +51,15 @@ object MuseumTooltipManager { private val loadedMuseumDataDelegate = lazy { var data = MuseumData() if (file.exists()) { - val content = file.readText() - val loadedData = Gson().fromJson(content, MuseumData::class.java) - if (loadedData != null) { - data = loadedData - } else { + try { + val content = file.readText() + val loadedData = Gson().fromJson(content, MuseumData::class.java) + if (loadedData != null) { + data = loadedData + } else { + Utils.addChatMessage("${EnumChatFormatting.RED}${EnumChatFormatting.BOLD}[NEU] Error while reading existing museum data, resetting.") + } + } catch (ignored: Exception) { Utils.addChatMessage("${EnumChatFormatting.RED}${EnumChatFormatting.BOLD}[NEU] Error while reading existing museum data, resetting.") } } else { -- cgit