fix: fail cleanly when game data is missing
This commit is contained in:
1 parent
bdfe2a1541
commit
00601b9140
2 files changed
+20
-4
No files matched your search
@@ -134,12 +134,15 @@ public sealed partial class GameData
|
||||
{
|
||||
log ??= _ => { };
|
||||
|
||||
var roots = sources.Where(Directory.Exists).ToArray();
|
||||
var wanted = sources.ToArray();
|
||||
var roots = wanted.Where(Directory.Exists).ToArray();
|
||||
|
||||
if (roots.Length == 0)
|
||||
{
|
||||
throw new DirectoryNotFoundException(
|
||||
"no game data sources found. Clone Dimbreath/turnbasedgamedata and point " +
|
||||
"Data:Sources at its ExcelOutput folder.");
|
||||
"no game data sources found. Clone Dimbreath/turnbasedgamedata and set Data:Sources " +
|
||||
"in config/config.json to its ExcelOutput folder. Looked in: " +
|
||||
(wanted.Length > 0 ? string.Join(", ", wanted) : "nowhere, Data:Sources is empty"));
|
||||
}
|
||||
|
||||
var data = new GameData(roots);
|
||||
|
||||
@@ -30,7 +30,18 @@ logger.LogInformation("protocol: {Count} commands", ProtocolRegistry.Count);
|
||||
var handlers = HandlerRegistry.Build(logger);
|
||||
logger.LogInformation("handlers: {Handlers} implemented", handlers.HandlerCount);
|
||||
|
||||
var world = new GameWorld(config, logger);
|
||||
GameWorld world;
|
||||
|
||||
try
|
||||
{
|
||||
world = new GameWorld(config, logger);
|
||||
}
|
||||
catch (DirectoryNotFoundException e)
|
||||
{
|
||||
// a fresh clone has no game data yet; say so plainly instead of dumping a stack trace
|
||||
logger.LogError("{Message}", e.Message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var gateway = new KcpGateway(
|
||||
config,
|
||||
@@ -46,3 +57,5 @@ Console.CancelKeyPress += (_, e) =>
|
||||
};
|
||||
|
||||
await gateway.RunAsync(cancellation.Token);
|
||||
|
||||
return 0;
|
||||
Reference in new issue
Block a user