Fix dotnet-counters and dotnet-trace CLI arg validator (#1989)
authorSung Yoon Whang <suwhang@microsoft.com>
Wed, 10 Feb 2021 19:54:50 +0000 (11:54 -0800)
committerGitHub <noreply@github.com>
Wed, 10 Feb 2021 19:54:50 +0000 (11:54 -0800)
* Make the CLI arg validator check for invalid process ID

* check for negative PID as well

* check for --diagnostic-port as well

src/Tools/Common/Commands/Utils.cs

index ab161fed204bbdfefacd3db0a9692e04982c2876..0d1ee6bb5c01b35978b597daaf94c8c73add599b 100644 (file)
@@ -53,7 +53,17 @@ namespace Microsoft.Internal.Common.Utils
         public static bool ValidateArguments(int processId, string name, string port, out int resolvedProcessId)
         {
             resolvedProcessId = -1;
-            if (processId != 0 && name != null && !string.IsNullOrEmpty(port))
+            if (processId == 0 && name == null && string.IsNullOrEmpty(port))
+            {
+                Console.WriteLine("Must specify either --process-id, --name, or --diagnostic-port.");
+                return false;
+            }
+            else if (processId < 0)
+            {
+                Console.WriteLine($"{processId} is not a valid process ID");
+                return false;
+            }
+            else if (processId != 0 && name != null && !string.IsNullOrEmpty(port))
             {
                 Console.WriteLine("Only one of the --name, --process-id, or --diagnostic-port options may be specified.");
                 return false;