Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ProxyOperationManager
private bool _testHostLaunched;
private int _testHostProcessId;
private string? _testHostProcessStdError;
private string? _testHostProcessFileName;

/// <summary>
/// Initializes a new instance of the <see cref="ProxyOperationManager"/> class.
Expand Down Expand Up @@ -231,6 +232,7 @@ public virtual bool SetupChannel(IEnumerable<string> sources, string? runSetting
sources,
envVars,
connectionInfo));
_testHostProcessFileName = testHostStartInfo.FileName;
try
{
// Launch the test host.
Expand Down Expand Up @@ -512,7 +514,7 @@ private void TestHostManagerHostExited(object? sender, HostProviderEventArgs? e)
// If not it reports timeout, if we don't set this before OnClientProcessExit we will
// report timeout even though we exited the test host before even attempting the connect.
_testHostExited.Set();
RequestSender.OnClientProcessExit(_testHostProcessStdError);
RequestSender.OnClientProcessExit(BuildCrashErrorContext(_testHostProcessFileName, _testHostProcessStdError));
}

private void ThrowOnTestHostExited(IEnumerable<string> sources, bool testHostExited)
Expand All @@ -521,7 +523,7 @@ private void ThrowOnTestHostExited(IEnumerable<string> sources, bool testHostExi
{
// We might consider passing standard output here in case standard error is not
// available because some errors don't end up in the standard error output.
throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, string.Join("', '", sources), _testHostProcessStdError));
throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, string.Join("', '", sources), BuildCrashErrorContext(_testHostProcessFileName, _testHostProcessStdError)));
}
}

Expand Down Expand Up @@ -552,12 +554,26 @@ private void ThrowExceptionOnConnectionFailure(IEnumerable<string> sources, int
}

// After testhost process launched failed with error.
if (!StringUtils.IsNullOrWhiteSpace(_testHostProcessStdError))
if (!StringUtils.IsNullOrWhiteSpace(_testHostProcessStdError) || !StringUtils.IsNullOrWhiteSpace(_testHostProcessFileName))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Error Reporting β€” Diagnostic Regression] The || !StringUtils.IsNullOrWhiteSpace(_testHostProcessFileName) addition causes this condition to fire on every launch attempt, not just on crashes.

_testHostProcessFileName is set unconditionally at line 235 (before LaunchTestHostAsync) and is never reset. This means the condition is true whenever any testhost has been launched, regardless of whether it actually crashed.

Consider the normal connection-timeout path (testhost running, never connected):

  • _testHostExited.IsSet = false β†’ ThrowOnTestHostExited doesn't throw, falls through to here
  • _testHostProcessStdError = "" (reset at start of SetupChannel, never updated since host didn't exit)
  • _testHostProcessFileName = "dotnet" or "testhost.exe" β†’ always truthy

Result: the informative timeout message (including process ID, elapsed seconds, and the environment variable hint) is overwritten with:

Testhost process for source(s) '...' exited with error: Process path: dotnet

The user sees a misleading "exited with error" message even though the process never exited β€” it just timed out.

Suggested fix: Keep the condition unchanged and instead append the path as context to the existing error messages, or scope the path to the errorMsg addendum only:

// After testhost process launched failed with error.
if (!StringUtils.IsNullOrWhiteSpace(_testHostProcessStdError))
{
    errorMsg = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError,
        string.Join("', '", sources),
        BuildCrashErrorContext(_testHostProcessFileName, _testHostProcessStdError));
}
else if (!StringUtils.IsNullOrWhiteSpace(_testHostProcessFileName))
{
    // Process launched but no stderr β€” append path as a diagnostic addendum.
    errorMsg += $" Process path: {_testHostProcessFileName}";
}

This preserves the existing diagnostic clarity for timeout scenarios while still surfacing the process path when it's the only available context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The || condition has been split into two cases:

  1. stderr present β†’ replace errorMsg with TestHostExitedWithError (crash path, unchanged behavior)
  2. no stderr, but path available β†’ append " Process path: {_testHostProcessFileName}" as an addendum to the existing timeout message, preserving the elapsed-seconds/process-ID/VSTEST_CONNECTION_TIMEOUT hint

This ensures connection-timeout diagnostics are never overwritten by a misleading "exited with error" message.

πŸ”§ Iterated by PR Iteration Agent πŸ”§

{
// Testhost failed with error.
errorMsg = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, string.Join("', '", sources), _testHostProcessStdError);
errorMsg = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestHostExitedWithError, string.Join("', '", sources), BuildCrashErrorContext(_testHostProcessFileName, _testHostProcessStdError));
}
Comment thread
azat-msft marked this conversation as resolved.
Resolved

throw new TestPlatformException(errorMsg);
}

private static string BuildCrashErrorContext(string? processFileName, string? stdError)
{
var hasPath = !StringUtils.IsNullOrWhiteSpace(processFileName);
var hasError = !StringUtils.IsNullOrWhiteSpace(stdError);

Comment thread
azat-msft marked this conversation as resolved.
Resolved
return (hasPath, hasError) switch
{
(true, true) => $"Process path: {processFileName}{Environment.NewLine}{stdError}",
(true, false) => $"Process path: {processFileName}",
(false, true) => stdError!,
_ => string.Empty,
};
Comment thread
azat-msft marked this conversation as resolved.
Resolved
}
}
Loading