Dev/mirogers/kudu console (#3083)
authormikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com>
Wed, 25 Jan 2023 04:28:42 +0000 (20:28 -0800)
committerGitHub <noreply@github.com>
Wed, 25 Jan 2023 04:28:42 +0000 (20:28 -0800)
* added some logging to debug in Kudu

* refined the placement of the try catch statement

* Create NamedPipeEnumerationUnauthorizedException and catch it

* fixing suggestions from code review

* stick with current exception type and specific message

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs
src/Tools/Common/Commands/ProcessStatus.cs

index c4cb1eab00e9af41a819460e23bbdbd2c5a416ed..22a89e45cd36044c020cfb0d8f7377f09917dc12 100644 (file)
@@ -305,9 +305,9 @@ namespace Microsoft.Diagnostics.NETCore.Client
         /// </returns>
         public static IEnumerable<int> GetPublishedProcesses()
         {
-            static IEnumerable<int> GetAllPublishedProcesses()
+            static IEnumerable<int> GetAllPublishedProcesses(string[] files)
             {
-                foreach (var port in Directory.GetFiles(PidIpcEndpoint.IpcRootPath))
+                foreach (var port in files)
                 {
                     var fileName = new FileInfo(port).Name;
                     var match = Regex.Match(fileName, PidIpcEndpoint.DiagnosticsPortPattern);
@@ -319,8 +319,22 @@ namespace Microsoft.Diagnostics.NETCore.Client
                     yield return processId;
                 }
             }
-
-            return GetAllPublishedProcesses().Distinct();
+            try 
+            {
+                string[] files = Directory.GetFiles(PidIpcEndpoint.IpcRootPath);
+                return GetAllPublishedProcesses(files).Distinct();
+            }
+            catch ( UnauthorizedAccessException ex)
+            {
+                if (PidIpcEndpoint.IpcRootPath.StartsWith(@"\\.\pipe"))
+                {
+                    throw new DiagnosticsClientException($"Enumerating {PidIpcEndpoint.IpcRootPath} is not authorized", ex);
+                }
+                else
+                {
+                    throw;
+                }
+            }
         }
 
         internal ProcessInfo GetProcessInfo()
index fa9aec630cff74cf8e23d2f6bd1eeba4945477f3..efcea1c4329cee571c401a4d9a3611eb7bbb1840 100644 (file)
@@ -8,6 +8,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
     public class DiagnosticsClientException : Exception
     {
         public DiagnosticsClientException(string msg) : base(msg) {}
+        public DiagnosticsClientException(string msg, Exception exception) : base(msg, exception) {}
     }
 
     // When a certian command is not supported by either the library or the target process' runtime
index 9a83d7c71aea529589a8984007368e45c5305653..72ea2f45daeaf0973a157d5ed26ab8b4a480dd6b 100644 (file)
@@ -142,7 +142,6 @@ namespace Microsoft.Internal.Common.Commands
                         String cmdLineArgs = GetArgs(process);
                         cmdLineArgs = cmdLineArgs == process.MainModule?.FileName ? string.Empty : cmdLineArgs;
                         string fileName = process.MainModule?.FileName ?? string.Empty;
-
                         var commandInfo = new ProcessDetails()
                         {
                             ProcessId = process.Id,
@@ -174,7 +173,7 @@ namespace Microsoft.Internal.Common.Commands
                 FormatTableRows(printInfo, sb);
                 console.Out.WriteLine(sb.ToString());
             }
-            catch (InvalidOperationException ex)
+            catch (Exception  ex)
             {
                 console.Out.WriteLine(ex.ToString());
             }