From 25ec0452a44a93181527e1a2e836611145706c23 Mon Sep 17 00:00:00 2001 From: j4ck <50369519+j4cegh@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:59:09 +0300 Subject: [PATCH] Better debug messages & some error handling --- RSND/Core/Database.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/RSND/Core/Database.cs b/RSND/Core/Database.cs index 67581fe..9cc163a 100644 --- a/RSND/Core/Database.cs +++ b/RSND/Core/Database.cs @@ -20,7 +20,7 @@ public class Database { if (File.Exists($"{Name}.json")) { - Console.WriteLine($"{Name} flag123"); + Console.WriteLine($"[{Name}] The file exists."); var json = File.ReadAllText($"{Name}.json"); var db = JsonConvert.DeserializeObject>(json); if (db != null) @@ -28,14 +28,23 @@ public class Database } else { - Console.WriteLine($"{Name} flag"); + Console.WriteLine($"[{Name}] The file is getting created."); File.Create($"{Name}.json"); } } public void Save() { - var json = JsonConvert.SerializeObject(_tables); - File.WriteAllText($"{Name}.json", json); + try + { + var json = JsonConvert.SerializeObject(_tables); + File.WriteAllText($"{Name}.json", json); + } + catch + { + // slim chance there might be file structure issues. + // let's attempt to fix that. + SetupFiles(); + } } public void CreateTable(Table query)