mirror of
https://github.com/Raymonf/whack.git
synced 2024-11-24 08:30:09 +01:00
very minor error handling for bulk imports
This commit is contained in:
parent
5bda007b63
commit
a59a0af2c0
18
WTT/WTT/Exceptions/UnhandledTomlError.cs
Normal file
18
WTT/WTT/Exceptions/UnhandledTomlError.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
namespace WhackTranslationTool.Exceptions;
|
||||||
|
|
||||||
|
public class UnhandledTomlError : Exception
|
||||||
|
{
|
||||||
|
public UnhandledTomlError()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnhandledTomlError(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnhandledTomlError(string message, Exception inner)
|
||||||
|
: base(message, inner)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -33,11 +33,16 @@ public class TableImporter
|
|||||||
|
|
||||||
private void ReadStrings(string tomlPath)
|
private void ReadStrings(string tomlPath)
|
||||||
{
|
{
|
||||||
using var reader = File.OpenText(tomlPath);
|
TomlTable? table = null;
|
||||||
TomlTable table;
|
|
||||||
|
var read = false;
|
||||||
|
while (!read)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using var reader = File.OpenText(tomlPath);
|
||||||
table = TOML.Parse(reader);
|
table = TOML.Parse(reader);
|
||||||
|
read = true;
|
||||||
}
|
}
|
||||||
catch (TomlParseException ex)
|
catch (TomlParseException ex)
|
||||||
{
|
{
|
||||||
@ -46,8 +51,22 @@ public class TableImporter
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"* Syntax error at line {error.Line}: {error.Message}");
|
Console.WriteLine($"* Syntax error at line {error.Line}: {error.Message}");
|
||||||
}
|
}
|
||||||
throw;
|
|
||||||
|
// prompt to retry so I don't have to keep restarting this thing
|
||||||
|
Console.Write("Try again (Y/n)? ");
|
||||||
|
var response = Console.ReadLine()!.Trim().ToLowerInvariant();
|
||||||
|
if (response is not ("" or "y" or "yes"))
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table == null)
|
||||||
|
{
|
||||||
|
throw new UnhandledTomlError("TOML error was not handled");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var (key, value) in table.RawTable)
|
foreach (var (key, value) in table.RawTable)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
|
Loading…
Reference in New Issue
Block a user