@@ -20,20 +20,17 @@ internal static class DebugProxyLauncher
20
20
private static readonly Regex ApplicationStartedRegex = new Regex ( @"^\s*Application started\. Press Ctrl\+C to shut down\.$" , RegexOptions . None , TimeSpan . FromSeconds ( 10 ) ) ;
21
21
private static readonly string [ ] MessageSuppressionPrefixes = new [ ]
22
22
{
23
- "Hosting environment:" ,
24
- "Content root path:" ,
25
- "Now listening on:" ,
26
- "Application started. Press Ctrl+C to shut down." ,
27
- } ;
23
+ "Hosting environment:" ,
24
+ "Content root path:" ,
25
+ "Now listening on:" ,
26
+ "Application started. Press Ctrl+C to shut down." ,
27
+ } ;
28
28
29
29
public static Task < string > EnsureLaunchedAndGetUrl ( IServiceProvider serviceProvider , string devToolsHost )
30
30
{
31
31
lock ( LaunchLock )
32
32
{
33
- if ( LaunchedDebugProxyUrl == null )
34
- {
35
- LaunchedDebugProxyUrl = LaunchAndGetUrl ( serviceProvider , devToolsHost ) ;
36
- }
33
+ LaunchedDebugProxyUrl ??= LaunchAndGetUrl ( serviceProvider , devToolsHost ) ;
37
34
38
35
return LaunchedDebugProxyUrl ;
39
36
}
@@ -54,6 +51,7 @@ private static async Task<string> LaunchAndGetUrl(IServiceProvider serviceProvid
54
51
Arguments = $ "exec \" { executablePath } \" --OwnerPid { ownerPid } --DevToolsUrl { devToolsHost } ",
55
52
UseShellExecute = false ,
56
53
RedirectStandardOutput = true ,
54
+ RedirectStandardError = true ,
57
55
} ;
58
56
RemoveUnwantedEnvironmentVariables ( processStartInfo . Environment ) ;
59
57
@@ -141,21 +139,40 @@ private static void PassThroughConsoleOutput(Process process)
141
139
private static void CompleteTaskWhenServerIsReady ( Process aspNetProcess , TaskCompletionSource < string > taskCompletionSource )
142
140
{
143
141
string ? capturedUrl = null ;
142
+ var errorEncountered = false ;
143
+
144
+ aspNetProcess . ErrorDataReceived += OnErrorDataReceived ;
145
+ aspNetProcess . BeginErrorReadLine ( ) ;
146
+
144
147
aspNetProcess . OutputDataReceived += OnOutputDataReceived ;
145
148
aspNetProcess . BeginOutputReadLine ( ) ;
146
149
150
+ void OnErrorDataReceived ( object sender , DataReceivedEventArgs eventArgs )
151
+ {
152
+ if ( ! string . IsNullOrEmpty ( eventArgs . Data ) )
153
+ {
154
+ taskCompletionSource . TrySetException ( new InvalidOperationException (
155
+ eventArgs . Data ) ) ;
156
+ errorEncountered = true ;
157
+ }
158
+ }
159
+
147
160
void OnOutputDataReceived ( object sender , DataReceivedEventArgs eventArgs )
148
161
{
149
162
if ( string . IsNullOrEmpty ( eventArgs . Data ) )
150
163
{
151
- taskCompletionSource . TrySetException ( new InvalidOperationException (
152
- "No output has been recevied from the application." ) ) ;
164
+ if ( ! errorEncountered )
165
+ {
166
+ taskCompletionSource . TrySetException ( new InvalidOperationException (
167
+ "Expected output has not been received from the application." ) ) ;
168
+ }
153
169
return ;
154
170
}
155
171
156
172
if ( ApplicationStartedRegex . IsMatch ( eventArgs . Data ) )
157
173
{
158
174
aspNetProcess . OutputDataReceived -= OnOutputDataReceived ;
175
+ aspNetProcess . ErrorDataReceived -= OnErrorDataReceived ;
159
176
if ( ! string . IsNullOrEmpty ( capturedUrl ) )
160
177
{
161
178
taskCompletionSource . TrySetResult ( capturedUrl ) ;
0 commit comments