Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report proper errors instead of NREs during trait and weapon linting #20082

Merged
merged 4 commits into from Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions OpenRA.Game/GameRules/WeaponInfo.cs
Expand Up @@ -139,7 +139,11 @@ static object LoadProjectile(MiniYaml yaml)
{
if (!yaml.ToDictionary().TryGetValue("Projectile", out var proj))
return null;

var ret = Game.CreateObject<IProjectileInfo>(proj.Value + "Info");
if (ret == null)
return null;

FieldLoader.Load(ret, proj);
return ret;
}
Expand All @@ -150,6 +154,9 @@ static object LoadWarheads(MiniYaml yaml)
foreach (var node in yaml.Nodes.Where(n => n.Key.StartsWith("Warhead")))
{
var ret = Game.CreateObject<IWarhead>(node.Value.Value + "Warhead");
if (ret == null)
continue;

FieldLoader.Load(ret, node.Value);
retList.Add(ret);
}
Expand Down
12 changes: 10 additions & 2 deletions OpenRA.Mods.Common/Lint/CheckUnknownTraitFields.cs
Expand Up @@ -64,13 +64,21 @@ void CheckActors(IEnumerable<MiniYamlNode> actors, Action<string> emitError, Mod
var traitName = NormalizeName(t.Key);

// Inherits can never define children
if (traitName == "Inherits" && t.Value.Nodes.Count > 0)
if (traitName == "Inherits")
{
emitError($"{t.Location} defines child nodes, which are not valid for Inherits.");
if (t.Value.Nodes.Count > 0)
emitError($"{t.Location} defines child nodes, which are not valid for Inherits.");

continue;
}

var traitInfo = modData.ObjectCreator.FindType(traitName + "Info");
if (traitInfo == null)
{
emitError($"{t.Location} defines unknown trait `{traitName}`.");
continue;
}

foreach (var field in t.Value.Nodes)
{
var fieldName = NormalizeName(field.Key);
Expand Down
12 changes: 12 additions & 0 deletions OpenRA.Mods.Common/Lint/CheckUnknownWeaponFields.cs
Expand Up @@ -68,6 +68,12 @@ void CheckWeapons(IEnumerable<MiniYamlNode> weapons, Action<string> emitError, A
{
var projectileName = NormalizeName(field.Value.Value);
var projectileInfo = modData.ObjectCreator.FindType(projectileName + "Info");
if (projectileInfo == null)
{
emitError($"{field.Location} defines unknown projectile `{projectileName}`.");
continue;
}

foreach (var projectileField in field.Value.Nodes)
{
var projectileFieldName = NormalizeName(projectileField.Key);
Expand All @@ -85,6 +91,12 @@ void CheckWeapons(IEnumerable<MiniYamlNode> weapons, Action<string> emitError, A

var warheadName = NormalizeName(field.Value.Value);
var warheadInfo = modData.ObjectCreator.FindType(warheadName + "Warhead");
if (warheadInfo == null)
{
emitError($"{field.Location} defines unknown warhead `{warheadName}`.");
continue;
}

foreach (var warheadField in field.Value.Nodes)
{
var warheadFieldName = NormalizeName(warheadField.Key);
Expand Down