Added try/catch for TypeDictionary errors in Lint code

TypeDictionary errors are very hard for modders to debug as they don't mention which actor is causing the error
This commit is contained in:
Gustas
2022-08-15 18:19:40 +03:00
committed by abcdefg30
parent cc58fe1a0f
commit d438508994
6 changed files with 135 additions and 88 deletions

View File

@@ -32,16 +32,24 @@ namespace OpenRA.Mods.Common.Lint
{
foreach (var actorInfo in rules.Actors)
{
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
foreach (var rsi in actorInfo.Value.TraitInfos<RevealsShroudInfo>())
// Catch TypeDictionary errors
try
{
if (rsi.Type != VisibilityType.Footprint)
continue;
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
foreach (var rsi in actorInfo.Value.TraitInfos<RevealsShroudInfo>())
{
if (rsi.Type != VisibilityType.Footprint)
continue;
if (ios == null)
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{rsi.GetType()}` but has no IOccupySpace traits!");
else if (ios.OccupiedCells(actorInfo.Value, CPos.Zero).Count == 0)
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{rsi.GetType()}` but does not have any footprint cells!");
if (ios == null)
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{rsi.GetType()}` but has no IOccupySpace traits!");
else if (ios.OccupiedCells(actorInfo.Value, CPos.Zero).Count == 0)
emitError($"Actor type `{actorInfo.Key}` defines VisibilityType.Footprint in `{rsi.GetType()}` but does not have any footprint cells!");
}
}
catch (InvalidOperationException e)
{
emitError($"{e.Message} (Actor type `{actorInfo.Key}`)");
}
}
}