Skip to content

Commit

Permalink
Print stack trace from executor (#2730)
Browse files Browse the repository at this point in the history
* Print stack tract from executor

When executor fails with an error print the message and the stacktrace

* Fix tests
  • Loading branch information
nohwnd authored Feb 3, 2021
1 parent c598e9e commit 6622e7b
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 9 deletions.
22 changes: 20 additions & 2 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<data name="IgnoredDuplicateConfiguration" xml:space="preserve">
<value>There are multiple configurations that have data collector FriendlyName as '{0}'. Duplicate configurations will be ignored in the test run.</value>
</data>
<data name="InnerException" xml:space="preserve">
<value>Inner exception:</value>
</data>
<data name="InvalidCondition" xml:space="preserve">
<value>Error: Invalid Condition '{0}'</value>
</data>
Expand Down Expand Up @@ -213,6 +216,9 @@
<data name="SettingsProviderNotFound" xml:space="preserve">
<value>Settings Provider named '{0}' was not found. The settings can not be loaded.</value>
</data>
<data name="StackTrace" xml:space="preserve">
<value>Stack trace:</value>
</data>
<data name="TestCaseFilterFormatException" xml:space="preserve">
<value>Incorrect format for TestCaseFilter {0}. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.</value>
</data>
Expand Down
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Při pokusu o vytvoření složky TestResults v uvedeném umístění došlo k odepření přístupu. Tato výjimka se vyvolala, protože spouštíte vstest.console.exe ze složky, která vyžaduje, abyste měli přístup pro zápis. Pokud chcete problém vyřešit, spusťte prosím vstest.console.exe ze složky, ve které máte oprávnění k zápisu. Další informace najdete v chybové zprávě:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Beim Erstellen des Ordners "TestResults" am angegebenen Speicherort wurde der Zugriff verweigert. Sie erhalten diese Ausnahme, weil Sie "vstest.console.exe" von einem Ordner aus ausführen, für den Schreibzugriff erforderlich ist. So beheben Sie das Problem: Führen Sie "vstest.console.exe" in einem Ordner aus, für den Sie Schreibberechtigungen besitzen. Weitere Informationen finden Sie in der Fehlermeldung:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Se denegó el acceso al intentar crear la carpeta "TestResults" en la ubicación mencionada. Está recibiendo esta excepción porque está ejecutando vstest.console.exe desde una carpeta que requiere acceso de escritura. Para solucionar el problema: ejecute vstest.console.exe desde una carpeta en la que tenga privilegios de escritura. Para obtener más información, consulte el mensaje de error:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Accès refusé durant la tentative de création du dossier "TestResults" à l'emplacement indiqué. Vous obtenez cette exception, car vous exécutez vstest.console.exe à partir d'un dossier qui nécessite un accès en écriture. Pour résoudre le problème, exécutez vstest.console.exe à partir d'un dossier sur lequel vous disposez de privilèges d'accès en écriture. Pour plus d'informations, consultez le message d'erreur :</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Accesso negato durante il tentativo di creare la cartella "TestResults" nel percorso indicato. Si riceve questa eccezione perché si esegue vstest.console.exe da una cartella per cui è necessario l'accesso in scrittura. Per risolvere il problema, eseguire vstest.console.exe da una cartella per cui si hanno privilegi di scrittura. Per altre informazioni, vedere il messaggio di errore:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} 記載した場所に "TestResults" フォルダーを作成しようとしたときにアクセスが拒否されました。書き込みアクセスを必要とするフォルダーから vstest.console.exe を実行しているため、この例外が発生しています。この問題を解決するには、書き込み権限のあるフォルダーから vstest.console.exe を実行してください。詳細については、次のエラー メッセージをご覧ください。</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} "TestResults" 폴더를 언급된 위치에 만드는 동안 액세스가 거부되었습니다. 쓰기 권한이 필요한 폴더에서 vstest.console.exe를 실행하고 있으므로 이 예외가 발생했습니다. 이 문제를 해결하려면 쓰기 권한이 있는 폴더에서 vstest.console.exe를 실행하세요. 자세한 내용은 다음 오류 메시지를 확인하세요.</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Odmowa dostępu podczas próby utworzenia folderu „TestResults” w określonej lokalizacji. Widzisz ten wyjątek, ponieważ program vstest.console.exe został uruchomiony z folderu wymagającego dostępu do zapisu. Aby rozwiązać ten problem: uruchom program vstest.console.exe z folderu, w którym masz uprawnienia do zapisu. Więcej informacji można znaleźć w komunikacie o błędzie:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Acesso negado ao tentar criar a pasta "TestResults" no local mencionado. Você está recebendo esta exceção porque está executando o vstest.console.exe em uma pasta que requer acesso para gravação. Para resolver o problema: execute vstest.console.exe em uma pasta na qual você tenha privilégios de gravação. Para obter mais informações, verifique a mensagem de erro:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Отказано в доступе при попытке создания папки "TestResults" в указанном расположении. Это исключение возникло, так как вы запускаете файл vstest.console.exe из папки, для которой требуется доступ на запись. Чтобы устранить эту проблему, запустите vstest.console.exe из папки, для которой у вас есть разрешения на запись. Дополнительные сведения см. в сообщении об ошибке:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} Belirtilen konumda "TestResults" klasörü oluşturulmaya çalışılırken erişim engellendi. Yazma erişimi gerektiren bir klasörden vstest.console.exe çalıştırdığınız için bu özel durumu aldınız. Sorunu çözmek için: Lütfen yazma ayrıcalıklarına sahip olduğunuz bir klasörden vstest.console.exe dosyasını çalıştırın. Daha fazla bilgi için lütfen hata iletisine bakın:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@
<target state="new">Access denied while trying to create "TestResults" folder in current location. You are getting this exception because you are running vstest.console.exe from a folder which requires administrator rights. To solve the issue : please open command line "As Administrator" or run vstest.console.exe from a folder where you have admin privileges.</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} 尝试在所述位置创建 "TestResults" 文件夹时,访问被拒。你收到此异常是因为你正在从需要具有写入权限的文件夹运行 vstest.console.exe。若要解决此问题,请从你具有写入权限的文件夹运行 vstest.console.exe。有关详细信息,请查看错误消息:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
<target state="translated">{0} 嘗試在提及的位置上建立 "TestResults" 資料夾時存取被拒。因為您正從需要寫入存取權的資料夾執行 vstest.console.exe,所以收到此例外狀況。若要解決此問題: 請從您有權寫入的資料夾執行 vstest.console.exe。如需詳細資訊,請參閱錯誤訊息:</target>
<note></note>
</trans-unit>
<trans-unit id="InnerException">
<source>Inner exception:</source>
<target state="new">Inner exception:</target>
<note></note>
</trans-unit>
<trans-unit id="StackTrace">
<source>Stack trace:</source>
<target state="new">Stack trace:</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
19 changes: 17 additions & 2 deletions src/Microsoft.TestPlatform.Common/Utilities/ExceptionUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ public static string GetExceptionMessage(Exception exception)
}

var exceptionString = new StringBuilder(exception.Message);
AppendStackTrace(exceptionString, exception);

var inner = exception.InnerException;
while (inner != null)
{
exceptionString.Append(Environment.NewLine);
exceptionString.Append(inner.Message);
exceptionString
.AppendLine()
.Append(Resources.Resources.InnerException).Append(" ").AppendLine(inner.Message);
AppendStackTrace(exceptionString, inner);
inner = inner.InnerException;
}

return exceptionString.ToString();
}

private static void AppendStackTrace(StringBuilder stringBuilder, Exception exception)
{
if (!string.IsNullOrEmpty(exception.StackTrace))
{
stringBuilder
.AppendLine()
.AppendLine(Resources.Resources.StackTrace)
.AppendLine(exception.StackTrace);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,39 @@ public void GetExceptionMessageShouldReturnExceptionMessage()
}

[TestMethod]
public void GetExceptionMessageShouldReturnFormattedExceptionMessageWithInnerExceptionDetails()
public void GetExceptionMessageShouldReturnExceptionMessageContainingAllExceptionMessages()
{
var innerException = new Exception("Bad stuff internally");
var innerException2 = new Exception("Bad stuff internally 2", innerException);
var exception = new ArgumentException("Some bad stuff", innerException2);
var expectedMessage = exception.Message + Environment.NewLine + innerException2.Message
+ Environment.NewLine + innerException.Message;
Assert.AreEqual(expectedMessage, ExceptionUtilities.GetExceptionMessage(exception));

var message = ExceptionUtilities.GetExceptionMessage(exception);
StringAssert.Contains(message, exception.Message);
StringAssert.Contains(message, innerException.Message);
StringAssert.Contains(message, innerException.Message);
}

[TestMethod]
public void GetExceptionMessageShouldReturnExceptionMessageContainingStackTrace()
{
var message = ExceptionUtilities.GetExceptionMessage(GetExceptionWithStackTrace());
StringAssert.Contains(message, "Stack trace:");
// this test is where it or
StringAssert.Contains(message, "ExceptionUtilitiesTests.GetExceptionWithStackTrace");
}

private Exception GetExceptionWithStackTrace()
{
try
{
var innerException = new Exception("Bad stuff internally");
var innerException2 = new Exception("Bad stuff internally 2", innerException);
throw new ArgumentException("Some bad stuff", innerException2);
}
catch (Exception e)
{
return e;
}
}
}
}
Loading

0 comments on commit 6622e7b

Please sign in to comment.