From 780f905959753f78df5688f5f6231e2fc47590e7 Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Thu, 22 Oct 2015 18:46:51 -0500 Subject: [PATCH 1/2] Fix misleading Utility message We were reporting that the entered command did not exist by assuming that any ArgumentException indicated this. Now we will throw and catch a NoSuchCommandException. --- OpenRA.Utility/Program.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 3913994844..1801718107 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -15,6 +15,16 @@ using OpenRA.FileSystem; namespace OpenRA.Utility { + public class NoSuchCommandException : Exception + { + public readonly string Command; + public NoSuchCommandException(string command) + : base("No such command '{0}'".F(command)) + { + Command = command; + } + } + class Program { static void Main(string[] args) @@ -57,7 +67,7 @@ namespace OpenRA.Utility try { if (!actions.ContainsKey(args[0])) - throw new ArgumentException(); + throw new NoSuchCommandException(args[0]); var action = actions[args[0]].Key; var validateActionArgs = actions[args[0]].Value; @@ -78,13 +88,13 @@ namespace OpenRA.Utility Log.Write("utility", "Received args: {0}", args.JoinWith(" ")); Log.Write("utility", "{0}", e); - if (e is ArgumentException) - Console.WriteLine("No such command '{0}'", args[0]); - else - { - Console.WriteLine("Error: Utility application crashed. See utility.log for details"); - throw; - } + if (e is NoSuchCommandException) + Console.WriteLine(e.Message); + else + { + Console.WriteLine("Error: Utility application crashed. See utility.log for details"); + throw; + } } } From 9ab5eacdee40a7a23078d8d857d4312626af5e4b Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Thu, 22 Oct 2015 18:48:25 -0500 Subject: [PATCH 2/2] Cache the command entered in a variable in Utility.Program.cs for easier reading. --- OpenRA.Utility/Program.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 1801718107..c32662ab75 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -66,11 +66,12 @@ namespace OpenRA.Utility try { - if (!actions.ContainsKey(args[0])) - throw new NoSuchCommandException(args[0]); + var command = args[0]; + if (!actions.ContainsKey(command)) + throw new NoSuchCommandException(command); - var action = actions[args[0]].Key; - var validateActionArgs = actions[args[0]].Value; + var action = actions[command].Key; + var validateActionArgs = actions[command].Value; if (validateActionArgs.Invoke(args)) { @@ -78,8 +79,8 @@ namespace OpenRA.Utility } else { - Console.WriteLine("Invalid arguments for '{0}'", args[0]); - GetActionUsage(args[0], action); + Console.WriteLine("Invalid arguments for '{0}'", command); + GetActionUsage(command, action); } } catch (Exception e)