Skip to content

Commit f6b0b96

Browse files
isra-felYeming Liu
and
Yeming Liu
authored
Handles NullRefEx of PSStyle in automation runbooks (#446)
Co-authored-by: Yeming Liu <[email protected]>
1 parent 8403059 commit f6b0b96

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Common/ColorAndFormat/PSStyle.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public sealed class PSStyle
3131
/// <param name="host">PowerShell Console Host</param>
3232
public static void Initialize(PSHost host)
3333
{
34-
_isEscapeSequenceSupported = host?.UI?.SupportsVirtualTerminal;
34+
try
35+
{
36+
_isEscapeSequenceSupported = host?.UI?.SupportsVirtualTerminal;
37+
}
38+
catch (System.Exception) {
39+
// Ignore exception and set _isEscapeSequenceSupported to null.
40+
// The getter of SupportsVirtualTerminal can throw a null reference exception in automation runbooks.
41+
// see https://github.com/Azure/azure-powershell/issues/26155
42+
}
3543
}
3644

3745
/// <summary>

0 commit comments

Comments
 (0)