-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Enable nullable: System.Management.Automation.IContainsErrorRecord #14166
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
Enable nullable: System.Management.Automation.IContainsErrorRecord #14166
Conversation
|
The checks I see are of the type var icer = exception as IContainsErrorRecord;
if (icer == null)...But that is just checking for the interface. /// <summary>
/// Encode exception.
/// </summary>
private static PSObject EncodeException(Exception exception)
{
// We are encoding exceptions as ErrorRecord objects because exceptions written
// to the wire are lost during serialization. By sending across ErrorRecord objects
// we are able to preserve the exception as well as the stack trace.
ErrorRecord errorRecord = null;
IContainsErrorRecord containsErrorRecord = exception as IContainsErrorRecord;
if (containsErrorRecord == null)
{
// If this is a .NET exception then wrap in an ErrorRecord.
errorRecord = new ErrorRecord(exception, "RemoteHostExecutionException", ErrorCategory.NotSpecified, null);
}
else
{
// Exception inside the error record is ParentContainsErrorRecordException which
// doesn't have stack trace. Replace it with top level exception.
errorRecord = containsErrorRecord.ErrorRecord;
errorRecord = new ErrorRecord(errorRecord, exception);
}
PSObject errorRecordPSObject = RemotingEncoder.CreateEmptyPSObject();
errorRecord.ToPSObjectForRemoting(errorRecordPSObject);
return errorRecordPSObject;
}And public ErrorRecord(ErrorRecord errorRecord,
Exception replaceParentContainsErrorRecordException)
{
if (errorRecord == null)
{
throw new PSArgumentNullException(nameof(errorRecord));
}
}Clearly, the expectation is that it is non-null. I don't think the checks you see for null are what you think they are. |
|
I think those checks are just extra precautions since we haven't had a language mechanism to help us with this. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Tracking issue: #12631.