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,13 +32,21 @@ namespace OpenRA.Mods.Common.Lint
{
foreach (var actorInfo in rules.Actors)
{
var buildable = actorInfo.Value.TraitInfoOrDefault<BuildableInfo>();
if (buildable == null)
continue;
// Catch TypeDictionary errors
try
{
var buildable = actorInfo.Value.TraitInfoOrDefault<BuildableInfo>();
if (buildable == null)
continue;
var tooltip = actorInfo.Value.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
if (tooltip == null)
emitError("The following buildable actor has no (enabled) Tooltip: " + actorInfo.Key);
var tooltip = actorInfo.Value.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
if (tooltip == null)
emitError("The following buildable actor has no (enabled) Tooltip: " + actorInfo.Key);
}
catch (InvalidOperationException e)
{
emitError($"{e.Message} (Actor type `{actorInfo.Key}`)");
}
}
}
}