Skip to content

Commit de87f37

Browse files
Adding empty remote message check in the SystemLogger (#11473)
* Adding empty string check.
1 parent 1d92579 commit de87f37

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
-->
66
- Adding a "web app" configuration profile (#11447)
77
- Add JitTrace Files for v4.1045
8+
- Adding empty remote message check in the SystemLogger (#11473)

src/WebJobs.Script.WebHost/Extensions/ExceptionExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ public static (string InnerExceptionType, string InnerExceptionMessage, string D
6363
var formattedDetails = exception.ToFormattedString();
6464

6565
if (exception is FunctionInvocationException && baseException is RpcException { RemoteMessage: var remoteMsg }
66-
&& remoteMsg is not null)
66+
&& !string.IsNullOrWhiteSpace(remoteMsg))
6767
{
6868
var redacted = GetRedactedExceptionMessage(remoteMsg);
6969

70-
var innerExceptionMessage = Sanitizer.Sanitize(
71-
originalMessage.Replace(remoteMsg, redacted, StringComparison.Ordinal));
70+
var innerExceptionMessage = string.IsNullOrWhiteSpace(originalMessage)
71+
? string.Empty
72+
: Sanitizer.Sanitize(originalMessage.Replace(remoteMsg, redacted, StringComparison.Ordinal));
7273

73-
var detailsSanitized = Sanitizer.Sanitize(
74-
formattedDetails.Replace(remoteMsg, redacted, StringComparison.Ordinal));
74+
var detailsSanitized = string.IsNullOrWhiteSpace(formattedDetails)
75+
? string.Empty
76+
: Sanitizer.Sanitize(formattedDetails.Replace(remoteMsg, redacted, StringComparison.Ordinal));
7577

7678
return (innerType, innerExceptionMessage, detailsSanitized, formattedMessage);
7779
}

test/WebJobs.Script.Tests/Extensions/ExceptionExtensionsTests.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5+
using Microsoft.Azure.WebJobs.Host;
6+
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
57
using Xunit;
68

79
namespace Microsoft.Azure.WebJobs.Script.Tests.Extensions
@@ -31,7 +33,55 @@ public void GetExceptionDetails_ReturnsExpectedResult()
3133
Assert.Contains("System.Exception : some outer exception ---> System.InvalidOperationException : Some inner exception", exceptionDetails);
3234
Assert.Contains("End of inner exception", exceptionDetails);
3335
Assert.Contains("at Microsoft.Azure.WebJobs.Script.Tests.Extensions.ExceptionExtensionsTests.GetExceptionDetails_ReturnsExpectedResult()", exceptionDetails);
34-
Assert.Contains("ExceptionExtensionsTests.cs : 20", exceptionDetails);
36+
Assert.Contains("ExceptionExtensionsTests.cs", exceptionDetails);
37+
}
38+
39+
[Fact]
40+
public void GetExceptionDetails_Rpc()
41+
{
42+
string rpcMessage = "rpcMessage";
43+
Exception innerException = new RpcException("result", rpcMessage, "stack");
44+
Exception outerException = new FunctionInvocationException("message", innerException);
45+
Exception fullException;
46+
47+
try
48+
{
49+
throw outerException;
50+
}
51+
catch (Exception e)
52+
{
53+
fullException = e;
54+
}
55+
56+
(string exceptionType, string exceptionMessage, string exceptionDetails, string formattedText) = fullException.GetSanitizedExceptionDetails("safe text");
57+
58+
Assert.Equal("Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException", exceptionType);
59+
Assert.DoesNotContain(rpcMessage, exceptionMessage);
60+
Assert.DoesNotContain(rpcMessage, exceptionDetails);
61+
Assert.Contains("safe text", formattedText);
62+
}
63+
64+
[Fact]
65+
public void GetExceptionDetails_Rpc_Empty()
66+
{
67+
Exception innerException = new RpcException(string.Empty, string.Empty, string.Empty);
68+
Exception outerException = new FunctionInvocationException(string.Empty, innerException);
69+
Exception fullException;
70+
71+
try
72+
{
73+
throw outerException;
74+
}
75+
catch (Exception e)
76+
{
77+
fullException = e;
78+
}
79+
80+
(string exceptionType, string exceptionMessage, _, string formattedText) = fullException.GetSanitizedExceptionDetails("safe text");
81+
82+
Assert.Equal("Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException", exceptionType);
83+
Assert.Equal("Result: \nType: \nException: \nStack: ", exceptionMessage);
84+
Assert.Contains("safe text", formattedText);
3585
}
3686
}
3787
}

0 commit comments

Comments
 (0)