From c08ae1fa828d984a6dd4a0dde0f3ceeee29f981c Mon Sep 17 00:00:00 2001 From: Paul Hutchings Date: Sat, 23 Nov 2024 21:44:51 -0500 Subject: [PATCH 1/3] Add test case for parsing failure --- .../Plugins/Order/PluginListingsParserTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs b/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs index fae95efdd8..6d4f9f22a1 100644 --- a/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs +++ b/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs @@ -73,4 +73,22 @@ public void CommentTrimming() new LoadOrderListing("ModB.esp", false), new LoadOrderListing("ModC.esp", true)); } + + [Fact] + public void PrintLinesOnFailure() + { + var parser = new PluginListingsParser( + new PluginListingCommentTrimmer(), + new LoadOrderListingParser( + new HasEnabledMarkersInjection(true))); + + parser.Invoking(p => p.Parse(GetStream( +@"*ModA.esm +ModB.esp +*Malformed")) + .ToList()) + .Should() + .Throw() + .WithMessage("Load order file had malformed line at line 3: \"*Malformed\""); + } } \ No newline at end of file From 6b097c6e06e9d4f03948431445e7c0934a9e706e Mon Sep 17 00:00:00 2001 From: Paul Hutchings Date: Sat, 23 Nov 2024 21:51:37 -0500 Subject: [PATCH 2/3] Update PluginListingsParser.Parse to print line errors --- .../Plugins/Order/DI/PluginListingsParser.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs b/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs index b502670772..9bee7e9a06 100644 --- a/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs +++ b/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs @@ -30,13 +30,23 @@ public PluginListingsParser( /// public IEnumerable Parse(Stream stream) { + uint currentLine = 0; using var streamReader = new StreamReader(stream); while (!streamReader.EndOfStream) { + currentLine++; var str = streamReader.ReadLine().AsSpan(); str = _commentTrimmer.Trim(str); if (MemoryExtensions.IsWhiteSpace(str) || str.Length == 0) continue; - yield return _listingParser.FromString(str); + + if (_listingParser.TryFromString(str, out var listing)) + { + yield return listing; + } + else + { + throw new InvalidDataException($"Load order file had malformed line at line {currentLine}: \"{str}\""); + } } } } \ No newline at end of file From 23b5dda26430db10ce7f5076b10b59fbc629bb64 Mon Sep 17 00:00:00 2001 From: Paul Hutchings Date: Sun, 24 Nov 2024 19:39:30 -0500 Subject: [PATCH 3/3] Update error message --- .../Plugins/Order/PluginListingsParserTests.cs | 2 +- Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs b/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs index 6d4f9f22a1..b0e9a49aae 100644 --- a/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs +++ b/Mutagen.Bethesda.Core.UnitTests/Plugins/Order/PluginListingsParserTests.cs @@ -89,6 +89,6 @@ public void PrintLinesOnFailure() .ToList()) .Should() .Throw() - .WithMessage("Load order file had malformed line at line 3: \"*Malformed\""); + .WithMessage("Load order file had malformed entry at line 3: \"*Malformed\""); } } \ No newline at end of file diff --git a/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs b/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs index 9bee7e9a06..632a9f2a5e 100644 --- a/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs +++ b/Mutagen.Bethesda.Core/Plugins/Order/DI/PluginListingsParser.cs @@ -45,7 +45,7 @@ public IEnumerable Parse(Stream stream) } else { - throw new InvalidDataException($"Load order file had malformed line at line {currentLine}: \"{str}\""); + throw new InvalidDataException($"Load order file had malformed entry at line {currentLine}: \"{str}\""); } } }