From f4b0e8b59efb99ff56baadfdeb312d73032b96c0 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Fri, 3 Apr 2026 03:41:21 +0100 Subject: [PATCH] improve file reading error handling --- OemLoader/MainWindow.cs | 11 +++++++++-- OemLoader/OemDataLine.cs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/OemLoader/MainWindow.cs b/OemLoader/MainWindow.cs index 8469d6c..2c3b000 100644 --- a/OemLoader/MainWindow.cs +++ b/OemLoader/MainWindow.cs @@ -72,8 +72,15 @@ public class MainWindow(string title) try { _oem = OemDataLine.ReadFile(_filename.ToString()); - _sliderTicks = _oem.First().Epoch.Ticks; - _errorMessage = null; + if (_oem is not null) + { + _sliderTicks = _oem.First().Epoch.Ticks; + _errorMessage = null; + } + else + { + _errorMessage = "Could not find any ephemeris data in file"; + } } catch (Exception e) { diff --git a/OemLoader/OemDataLine.cs b/OemLoader/OemDataLine.cs index 210744f..98c4670 100644 --- a/OemLoader/OemDataLine.cs +++ b/OemLoader/OemDataLine.cs @@ -42,7 +42,7 @@ public partial struct OemDataLine [GeneratedRegex(@"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d{3})?(\s+-?\d+(.\d+)){6,}$")] private static partial Regex OemLineRegex { get; } - public static List ReadFile(string path) + public static List? ReadFile(string path) { var data = new List(); var lines = File.ReadAllLines(path); @@ -54,6 +54,6 @@ public partial struct OemDataLine } } - return data; + return data.Count == 0 ? null : data; } } \ No newline at end of file -- 2.51.2