From 14f1ffd31f90b0600585efa83be96ce91b643613 Mon Sep 17 00:00:00 2001 From: Ionite Date: Tue, 6 Feb 2024 21:15:19 -0500 Subject: [PATCH] Error handling for index checkpoints --- CHANGELOG.md | 1 + .../Services/SettingsManager.cs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d14700d..79e17f0d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2 - Improved error messages with process output for 7z extraction errors - Fixed missing tkinter dependency for OneTrainer on Windows - Fixed auto-update on macOS not starting new version from an issue in starting .app bundles with arguments +- Fixed [#436](https://github.com/LykosAI/StabilityMatrix/issues/436) - Crash on invalid json files during checkpoint indexing ## v2.8.0 ### Added diff --git a/StabilityMatrix.Core/Services/SettingsManager.cs b/StabilityMatrix.Core/Services/SettingsManager.cs index 4959227be..b7441cf42 100644 --- a/StabilityMatrix.Core/Services/SettingsManager.cs +++ b/StabilityMatrix.Core/Services/SettingsManager.cs @@ -425,11 +425,22 @@ public void IndexCheckpoints() foreach (var jsonFile in connectedModelJsons) { var json = File.ReadAllText(jsonFile); - var connectedModel = JsonSerializer.Deserialize(json); - if (connectedModel?.Hashes.BLAKE3 != null) + if (string.IsNullOrWhiteSpace(json)) + continue; + + try + { + var connectedModel = JsonSerializer.Deserialize(json); + + if (connectedModel?.Hashes.BLAKE3 != null) + { + modelHashes.Add(connectedModel.Hashes.BLAKE3); + } + } + catch (Exception e) { - modelHashes.Add(connectedModel.Hashes.BLAKE3); + Logger.Warn(e, "Failed to parse connected model info from {JsonFile}", jsonFile); } }