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

@@ -33,14 +33,21 @@ namespace OpenRA.Mods.Common.Lint
var providedPrereqs = rules.Actors.SelectMany(a => a.Value.TraitInfos<ITechTreePrerequisiteInfo>().SelectMany(p => p.Prerequisites(a.Value)));
// TODO: this check is case insensitive while the real check in-game is not
foreach (var i in rules.Actors)
foreach (var actorInfo in rules.Actors)
{
var bi = i.Value.TraitInfoOrDefault<BuildableInfo>();
if (bi != null)
foreach (var prereq in bi.Prerequisites)
if (!prereq.StartsWith("~disabled"))
if (!providedPrereqs.Contains(prereq.Replace("!", "").Replace("~", "")))
emitError($"Buildable actor {i.Key} has prereq {prereq} not provided by anything.");
// Catch TypeDictionary errors
try
{
var bi = actorInfo.Value.TraitInfoOrDefault<BuildableInfo>();
if (bi != null)
foreach (var prereq in bi.Prerequisites)
if (!prereq.StartsWith("~disabled") && !providedPrereqs.Contains(prereq.Replace("!", "").Replace("~", "")))
emitError($"Buildable actor {actorInfo.Key} has prereq {prereq} not provided by anything.");
}
catch (InvalidOperationException e)
{
emitError($"{e.Message} (Actor type `{actorInfo.Key}`)");
}
}
}
}