@@ -83,8 +83,8 @@ public void CollectLinuxCommand_ReportsResolveProcessErrors()
8383 var args = TestArgs ( processId : - 1 ) ;
8484 int exitCode = Run ( args , console ) ;
8585
86- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
87- console . AssertSanitizedLinesEqual ( null , FormatException ( "-1 is not a valid process ID" ) ) ;
86+ Assert . Equal ( ( int ) ReturnCode . TracingError , exitCode ) ;
87+ console . AssertSanitizedLinesEqual ( null , FormatConnectionFailedError ( "" , - 1 ) ) ;
8888 }
8989
9090 [ ConditionalFact ( nameof ( IsCollectLinuxSupported ) ) ]
@@ -94,19 +94,19 @@ public void CollectLinuxCommand_ReportsResolveProcessNameErrors()
9494 var args = TestArgs ( name : "process-that-should-not-exist" , processId : 0 ) ;
9595 int exitCode = Run ( args , console ) ;
9696
97- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
98- console . AssertSanitizedLinesEqual ( null , FormatException ( "There is no active process with the given name: process -that-should-not-exist") ) ;
97+ Assert . Equal ( ( int ) ReturnCode . TracingError , exitCode ) ;
98+ console . AssertSanitizedLinesEqual ( null , FormatConnectionFailedError ( " process-that-should-not-exist", - 1 ) ) ;
9999 }
100100
101101 [ ConditionalTheory ( nameof ( IsCollectLinuxSupported ) ) ]
102102 [ MemberData ( nameof ( ResolveProcessExceptions ) ) ]
103- public void CollectLinuxCommand_ResolveProcessExceptions ( object testArgs , string [ ] expectedError )
103+ public void CollectLinuxCommand_ResolveProcessExceptions ( object testArgs , string [ ] expectedError , int expectedExitCode )
104104 {
105105 MockConsole console = new ( 200 , 30 , _outputHelper ) ;
106106
107107 int exitCode = Run ( testArgs , console ) ;
108108
109- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
109+ Assert . Equal ( expectedExitCode , exitCode ) ;
110110 console . AssertSanitizedLinesEqual ( null , expectedError ) ;
111111 }
112112
@@ -120,10 +120,10 @@ public void CollectLinuxCommand_Probe_ListsProcesses_WhenNoArgs()
120120 Assert . Equal ( ( int ) ReturnCode . Ok , exitCode ) ;
121121 string [ ] expected = ExpectPreviewWithMessages (
122122 new [ ] {
123- "Probing .NET processes for support of the EventPipe UserEvents IPC command used by collect-linux. Requires runtime '10.0.0' or later." ,
124- ".NET processes that support the command:" ,
123+ "Probing processes for support of the EventPipe UserEvents IPC command used by collect-linux. Requires runtime '10.0.0' or later." ,
124+ "Processes that support the command:" ,
125125 "" ,
126- ".NET processes that do NOT support the command:" ,
126+ "Processes that do NOT support the command:" ,
127127 "" ,
128128 }
129129 ) ;
@@ -170,12 +170,17 @@ public void CollectLinuxCommand_Probe_Csv()
170170 public void CollectLinuxCommand_Probe_ReportsResolveProcessErrors_InvalidPid ( )
171171 {
172172 MockConsole console = new ( 200 , 30 , _outputHelper ) ;
173- var args = TestArgs ( processId : - 1 , probe : true ) ;
173+ var args = TestArgs ( processId : - 1 , probe : true , output : new FileInfo ( CommonOptions . DefaultTraceName ) ) ;
174174 int exitCode = Run ( args , console ) ;
175175
176- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
176+ Assert . Equal ( ( int ) ReturnCode . Ok , exitCode ) ;
177177
178- string [ ] expected = FormatException ( "-1 is not a valid process ID" ) ;
178+ // ResolveProcess sets resolvedProcessName to the input name (empty string) before throwing
179+ string [ ] expected = ExpectPreviewWithMessages (
180+ new [ ] {
181+ "Process ' (-1)' could not be probed. Unable to connect to the process's diagnostic endpoint." ,
182+ }
183+ ) ;
179184
180185 console . AssertSanitizedLinesEqual ( null , expected ) ;
181186 }
@@ -184,12 +189,16 @@ public void CollectLinuxCommand_Probe_ReportsResolveProcessErrors_InvalidPid()
184189 public void CollectLinuxCommand_Probe_ReportsResolveProcessErrors_InvalidName ( )
185190 {
186191 MockConsole console = new ( 200 , 30 , _outputHelper ) ;
187- var args = TestArgs ( name : "process-that-should-not-exist" , processId : 0 , probe : true ) ;
192+ var args = TestArgs ( name : "process-that-should-not-exist" , processId : 0 , probe : true , output : new FileInfo ( CommonOptions . DefaultTraceName ) ) ;
188193 int exitCode = Run ( args , console ) ;
189194
190- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
195+ Assert . Equal ( ( int ) ReturnCode . Ok , exitCode ) ;
191196
192- string [ ] expected = FormatException ( "There is no active process with the given name: process-that-should-not-exist" ) ;
197+ string [ ] expected = ExpectPreviewWithMessages (
198+ new [ ] {
199+ "Process 'process-that-should-not-exist (-1)' could not be probed. Unable to connect to the process's diagnostic endpoint." ,
200+ }
201+ ) ;
193202
194203 console . AssertSanitizedLinesEqual ( null , expected ) ;
195204 }
@@ -198,14 +207,17 @@ public void CollectLinuxCommand_Probe_ReportsResolveProcessErrors_InvalidName()
198207 public void CollectLinuxCommand_Probe_ReportsResolveProcessErrors_BothPidAndName ( )
199208 {
200209 MockConsole console = new ( 200 , 30 , _outputHelper ) ;
201- var args = TestArgs ( name : "dummy" , processId : 1 , probe : true ) ;
210+ var args = TestArgs ( name : "dummy" , processId : 1 , probe : true , output : new FileInfo ( CommonOptions . DefaultTraceName ) ) ;
202211 int exitCode = Run ( args , console ) ;
203212
204- Assert . Equal ( ( int ) ReturnCode . ArgumentError , exitCode ) ;
213+ Assert . Equal ( ( int ) ReturnCode . Ok , exitCode ) ;
205214
206- // When both PID and name are supplied, the banner still refers to the PID
207- // because the implementation prioritizes ProcessId when it is non-zero.
208- string [ ] expected = FormatException ( "Only one of the --name or --process-id options may be specified." ) ;
215+ // When both PID and name are supplied, ResolveProcess throws early after setting resolvedPid to -1
216+ string [ ] expected = ExpectPreviewWithMessages (
217+ new [ ] {
218+ "Process 'dummy (-1)' could not be probed. Unable to connect to the process's diagnostic endpoint." ,
219+ }
220+ ) ;
209221
210222 console . AssertSanitizedLinesEqual ( null , expected ) ;
211223 }
@@ -386,22 +398,28 @@ public static IEnumerable<object[]> InvalidProviders()
386398
387399 public static IEnumerable < object [ ] > ResolveProcessExceptions ( )
388400 {
401+ // ResolveProcess sets resolvedProcessName to the input name (empty string) and resolvedPid to -1 before throwing
389402 yield return new object [ ]
390403 {
391404 TestArgs ( processId : - 1 , name : string . Empty ) ,
392- FormatException ( "-1 is not a valid process ID" )
405+ FormatConnectionFailedError ( "" , - 1 ) ,
406+ ( int ) ReturnCode . TracingError
393407 } ;
394408
409+ // When both PID and name are supplied, ResolveProcess throws early after setting resolvedPid to -1
395410 yield return new object [ ]
396411 {
397412 TestArgs ( processId : 1 , name : "dummy" ) ,
398- FormatException ( "Only one of the --name or --process-id options may be specified." )
413+ FormatConnectionFailedError ( "dummy" , - 1 ) ,
414+ ( int ) ReturnCode . TracingError
399415 } ;
400416
417+ // ResolveProcess sets resolvedPid to -1 before throwing when process doesn't exist
401418 yield return new object [ ]
402419 {
403420 TestArgs ( processId : int . MaxValue , name : string . Empty ) ,
404- FormatException ( "No process with ID 2147483647 is currently running." )
421+ FormatConnectionFailedError ( "" , - 1 ) ,
422+ ( int ) ReturnCode . TracingError
405423 } ;
406424 }
407425
@@ -423,6 +441,13 @@ private static string[] FormatException(string message)
423441 result . Add ( $ "[ERROR] { message } ") ;
424442 return result . ToArray ( ) ;
425443 }
444+ private static string [ ] FormatConnectionFailedError ( string processName , int pid )
445+ {
446+ List < string > result = new ( ) ;
447+ result . AddRange ( PreviewMessages ) ;
448+ result . Add ( $ "[ERROR] Unable to connect to process '{ processName } ({ pid } )'. The process may have exited or its diagnostic endpoint is not accessible.") ;
449+ return result . ToArray ( ) ;
450+ }
426451 private static string DefaultOutputFile => $ "Output File : { Directory . GetCurrentDirectory ( ) + Path . DirectorySeparatorChar } trace.nettrace";
427452 private static readonly string [ ] CommonTail = [
428453 DefaultOutputFile ,
0 commit comments