fix: extra error messages

This commit is contained in:
2026-02-19 08:41:43 +01:00
parent 96d9334b56
commit 2aeee0a009
2 changed files with 33 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CarManagerV3
@@ -52,6 +53,7 @@ namespace CarManagerV3
public static List<Car> ReadCars(string path)
{
List<Car> cars = new List<Car>();
List<string> failedLines = new List<string>();
try
{
using (StreamReader reader = new StreamReader(@path))
@@ -61,7 +63,13 @@ namespace CarManagerV3
{
// Process the line
if (line == "") continue;
cars.Add(Car.FromCsvString(line));
Car tmp = Car.FromCsvString(line);
if (tmp == null)
{
failedLines.Add(line);
continue;
}
cars.Add(tmp);
}
reader.Close();
}
@@ -69,6 +77,15 @@ namespace CarManagerV3
{
Console.Error.WriteLine($"Error reading cars from file: {ex.Message}");
}
if (failedLines.Count > 0)
{
Console.Error.WriteLine($"Warning: {failedLines.Count} lines could not be parsed and were skipped.");
foreach (string failedLine in failedLines)
{
Console.Error.WriteLine($"Failed line: {failedLine}");
}
MessageBox.Show($"Warning: {failedLines.Count} lines in the file could not be parsed and were skipped. Check the console for details.", "Parsing Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return cars;
}
@@ -92,6 +109,7 @@ namespace CarManagerV3
} catch (Exception ex)
{
Console.Error.WriteLine($"Error saving cars to file: {ex.Message}");
MessageBox.Show($"Error saving cars to file: {ex.Message}", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}