Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When formatting, if collection is modified, don't fail the entire pipeline #14438

Merged
merged 8 commits into from Jan 28, 2021
Expand Up @@ -7,6 +7,7 @@
using System.Collections.ObjectModel;
using System.Globalization;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Text;
Expand All @@ -19,6 +20,11 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary>
internal static class PSObjectHelper
{
#region tracer
[TraceSource("PSObjectHelper", "PSObjectHelper")]
internal static readonly PSTraceSource Tracer = PSTraceSource.GetTracer("PSObjectHelper", "PSObjectHelper");
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved
#endregion tracer

internal const char Ellipsis = '\u2026';

internal static string PSObjectIsOfExactType(Collection<string> typeNames)
Expand Down Expand Up @@ -290,10 +296,12 @@ internal static string SmartToString(PSObject so, PSPropertyExpressionFactory ex
// take care of the case there is no base object
return so.ToString();
}
catch (ExtendedTypeSystemException e)
catch (Exception e) when (e is ExtendedTypeSystemException || e is InvalidOperationException)
{
// NOTE: we catch all the exceptions, since we do not know
// what the underlying object access would throw
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved
// These exceptions are being caught and handled by returning an empty string when
// the object cannot be stringified due to ETS or an instance in the collection has been modified
Tracer.WriteLine("Exception during conversion to string, emitting empty string.");
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved

if (formatErrorObject != null)
{
formatErrorObject.sourceObject = so;
Expand Down