From 2f96015785b633a2f66b0663118eebc09c59c323 Mon Sep 17 00:00:00 2001 From: Mitchel Sellers Date: Wed, 10 Jan 2024 01:33:10 -0600 Subject: [PATCH] Fixes #25 by validating 0 length files --- src/GitHubCostVisualizer.Web/Controllers/HomeController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GitHubCostVisualizer.Web/Controllers/HomeController.cs b/src/GitHubCostVisualizer.Web/Controllers/HomeController.cs index a4d9dda..e1e4ac5 100644 --- a/src/GitHubCostVisualizer.Web/Controllers/HomeController.cs +++ b/src/GitHubCostVisualizer.Web/Controllers/HomeController.cs @@ -43,6 +43,11 @@ public IActionResult Report(HomeViewModel data) using (var csvData = new CsvReader(reader, CultureInfo.InvariantCulture)) { var rawReport = csvData.GetRecords().ToList(); + if (rawReport.Count == 0) + { + ModelState.AddModelError(nameof(data.UploadFile), "The uploaded file did not contain any records, please try with a different file."); + return View(nameof(Index), data); + } var model = _processor.ProcessUsageReport(rawReport); return View(model); }