forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log exception details from outermost exception (Azure#6680)
- Loading branch information
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/WebJobs.Script.Tests/Extensions/ExceptionExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Tests.Extensions | ||
{ | ||
public class ExceptionExtensionsTests | ||
{ | ||
[Fact] | ||
public void GetExceptionDetails_ReturnsExpectedResult() | ||
{ | ||
Exception innerException = new InvalidOperationException("Some inner exception"); | ||
Exception outerException = new Exception("some outer exception", innerException); | ||
Exception fullException; | ||
|
||
try | ||
{ | ||
throw outerException; | ||
} | ||
catch (Exception e) | ||
{ | ||
fullException = e; // Outer exception will have stack trace whereas the inner exception's stack trace will be null | ||
} | ||
|
||
(string exceptionType, string exceptionMessage, string exceptionDetails) = fullException.GetExceptionDetails(); | ||
|
||
Assert.Equal("System.InvalidOperationException", exceptionType); | ||
Assert.Equal("Some inner exception", exceptionMessage); | ||
Assert.Contains("System.Exception : some outer exception ---> System.InvalidOperationException : Some inner exception \r\n End of inner exception\r\n at Microsoft.Azure.WebJobs.Script.Tests.Extensions.ExceptionExtensionsTests.GetExceptionDetails_ReturnsExpectedResult()", exceptionDetails); | ||
Assert.Contains("Extensions\\ExceptionExtensionsTests.cs : 20", exceptionDetails); | ||
} | ||
} | ||
} |