Skip to content

Commit

Permalink
Log exception details from outermost exception (Azure#6680)
Browse files Browse the repository at this point in the history
  • Loading branch information
yojagad authored Sep 25, 2020
1 parent 83e9899 commit 126d6a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static (string exceptionType, string exceptionMessage, string exceptionDe

string exceptionType = innerException.GetType().ToString();
string exceptionMessage = Sanitizer.Sanitize(innerException.Message);
string exceptionDetails = Sanitizer.Sanitize(innerException.ToFormattedString());
string exceptionDetails = Sanitizer.Sanitize(exception.ToFormattedString());

return (exceptionType, exceptionMessage, exceptionDetails);
}
Expand Down
35 changes: 35 additions & 0 deletions test/WebJobs.Script.Tests/Extensions/ExceptionExtensionsTests.cs
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);
}
}
}

0 comments on commit 126d6a7

Please sign in to comment.