From deffc5faf9f026076fed9f50ba2f4480b84b325d Mon Sep 17 00:00:00 2001 From: penev92 Date: Mon, 20 Jun 2022 14:00:42 +0300 Subject: [PATCH] Added try/catch to CheckRevealFootprint Exceptions like "OpenRA.Utility(1,1): Error: OpenRA.Mods.Common.Lint.CheckDefaultVisibility failed with exception: System.InvalidOperationException: TypeDictionary contains multiple instances of type OpenRA.Traits.IOccupySpaceInfo" are very hard to diagnose, so we'd like to have the actor name to help. --- .../Lint/CheckRevealFootprint.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Lint/CheckRevealFootprint.cs b/OpenRA.Mods.Common/Lint/CheckRevealFootprint.cs index afcb63675fd4..ad68f0e72a0c 100644 --- a/OpenRA.Mods.Common/Lint/CheckRevealFootprint.cs +++ b/OpenRA.Mods.Common/Lint/CheckRevealFootprint.cs @@ -32,16 +32,23 @@ void Run(Action emitError, Ruleset rules) { foreach (var actorInfo in rules.Actors) { - var ios = actorInfo.Value.TraitInfoOrDefault(); - foreach (var rsi in actorInfo.Value.TraitInfos()) + try { - if (rsi.Type != VisibilityType.Footprint) - continue; + var ios = actorInfo.Value.TraitInfoOrDefault(); + foreach (var rsi in actorInfo.Value.TraitInfos()) + { + 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 (Exception e) + { + emitError($"Actor type `{actorInfo.Key}` caused an exception: {e}"); } } }