Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 131 additions & 49 deletions src/System.Management.Automation/engine/CoreAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,16 @@ private static Exception NewException(
{
Exception inner = ex.InnerException ?? ex;
newParameters[0] = inner.Message;
return new ExtendedTypeSystemException(targetErrorId,
return new ExtendedTypeSystemException(
targetErrorId,
inner,
resourceString,
newParameters);
}

newParameters[0] = e.Message;
return new ExtendedTypeSystemException(errorId,
return new ExtendedTypeSystemException(
errorId,
e,
resourceString,
newParameters);
Expand All @@ -380,8 +382,11 @@ internal ConsolidatedString BaseGetTypeNameHierarchy(object obj)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetTypeNameHierarchy", "CatchFromBaseGetTypeNameHierarchyTI",
ExtendedTypeSystem.ExceptionRetrievingTypeNameHierarchy);
throw NewException(
e,
"CatchFromBaseGetTypeNameHierarchy",
"CatchFromBaseGetTypeNameHierarchyTI",
ExtendedTypeSystem.ExceptionRetrievingTypeNameHierarchy);
}
}

Expand All @@ -394,8 +399,12 @@ internal T BaseGetMember<T>(object obj, string memberName) where T : PSMemberInf
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMember", "CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember, memberName);
throw NewException(
e,
"CatchFromBaseGetMember",
"CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember,
memberName);
}
}

Expand All @@ -408,8 +417,12 @@ internal T BaseGetFirstMemberOrDefault<T>(object obj, MemberNamePredicate predic
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMember", "CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember, nameof(predicate));
throw NewException(
e,
"CatchFromBaseGetMember",
"CatchFromBaseGetMemberTI",
ExtendedTypeSystem.ExceptionGettingMember,
nameof(predicate));
}
}

Expand All @@ -422,7 +435,10 @@ internal PSMemberInfoInternalCollection<T> BaseGetMembers<T>(object obj) where T
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseGetMembers", "CatchFromBaseGetMembersTI",
throw NewException(
e,
"CatchFromBaseGetMembers",
"CatchFromBaseGetMembersTI",
ExtendedTypeSystem.ExceptionGettingMembers);
}
}
Expand All @@ -440,15 +456,17 @@ internal object BasePropertyGet(PSProperty property)
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new GetValueInvocationException("CatchFromBaseAdapterGetValueTI",
throw new GetValueInvocationException(
"CatchFromBaseAdapterGetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, inner.Message);
}
catch (GetValueException) { throw; }
catch (Exception e)
{
throw new GetValueInvocationException("CatchFromBaseAdapterGetValue",
throw new GetValueInvocationException(
"CatchFromBaseAdapterGetValue",
e,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, e.Message);
Expand All @@ -464,15 +482,17 @@ internal void BasePropertySet(PSProperty property, object setValue, bool convert
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new SetValueInvocationException("CatchFromBaseAdapterSetValueTI",
throw new SetValueInvocationException(
"CatchFromBaseAdapterSetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, inner.Message);
}
catch (SetValueException) { throw; }
catch (Exception e)
{
throw new SetValueInvocationException("CatchFromBaseAdapterSetValue",
throw new SetValueInvocationException(
"CatchFromBaseAdapterSetValue",
e,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, e.Message);
Expand All @@ -488,8 +508,12 @@ internal bool BasePropertyIsSettable(PSProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyIsSettable", "CatchFromBasePropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyWriteState, property.Name);
throw NewException(
e,
"CatchFromBasePropertyIsSettable",
"CatchFromBasePropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyWriteState,
property.Name);
}
}

Expand All @@ -502,8 +526,12 @@ internal bool BasePropertyIsGettable(PSProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyIsGettable", "CatchFromBasePropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyReadState, property.Name);
throw NewException(
e,
"CatchFromBasePropertyIsGettable",
"CatchFromBasePropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyReadState,
property.Name);
}
}

Expand All @@ -516,8 +544,12 @@ internal string BasePropertyType(PSProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyType", "CatchFromBasePropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyType, property.Name);
throw NewException(
e,
"CatchFromBasePropertyType",
"CatchFromBasePropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyType,
property.Name);
}
}

Expand All @@ -530,8 +562,12 @@ internal string BasePropertyToString(PSProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyToString", "CatchFromBasePropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyString, property.Name);
throw NewException(
e,
"CatchFromBasePropertyToString",
"CatchFromBasePropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyString,
property.Name);
}
}

Expand All @@ -544,8 +580,12 @@ internal AttributeCollection BasePropertyAttributes(PSProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBasePropertyAttributes", "CatchFromBasePropertyAttributesTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyAttributes, property.Name);
throw NewException(
e,
"CatchFromBasePropertyAttributes",
"CatchFromBasePropertyAttributesTI",
ExtendedTypeSystem.ExceptionRetrievingPropertyAttributes,
property.Name);
}
}

Expand All @@ -561,10 +601,13 @@ internal object BaseMethodInvoke(PSMethod method, PSMethodInvocationConstraints
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new MethodInvocationException("CatchFromBaseAdapterMethodInvokeTI",
throw new MethodInvocationException(
"CatchFromBaseAdapterMethodInvokeTI",
inner,
ExtendedTypeSystem.MethodInvocationException,
method.Name, arguments.Length, inner.Message);
method.Name,
arguments.Length,
inner.Message);
}
catch (FlowControlException) { throw; }
catch (ScriptCallDepthException) { throw; }
Expand All @@ -580,10 +623,13 @@ internal object BaseMethodInvoke(PSMethod method, PSMethodInvocationConstraints
throw;
}

throw new MethodInvocationException("CatchFromBaseAdapterMethodInvoke",
throw new MethodInvocationException(
"CatchFromBaseAdapterMethodInvoke",
e,
ExtendedTypeSystem.MethodInvocationException,
method.Name, arguments.Length, e.Message);
method.Name,
arguments.Length,
e.Message);
}
}

Expand All @@ -596,8 +642,12 @@ internal Collection<string> BaseMethodDefinitions(PSMethod method)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseMethodDefinitions", "CatchFromBaseMethodDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingMethodDefinitions, method.Name);
throw NewException(
e,
"CatchFromBaseMethodDefinitions",
"CatchFromBaseMethodDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingMethodDefinitions,
method.Name);
}
}

Expand All @@ -610,8 +660,12 @@ internal string BaseMethodToString(PSMethod method)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseMethodToString", "CatchFromBaseMethodToStringTI",
ExtendedTypeSystem.ExceptionRetrievingMethodString, method.Name);
throw NewException(
e,
"CatchFromBaseMethodToString",
"CatchFromBaseMethodToStringTI",
ExtendedTypeSystem.ExceptionRetrievingMethodString,
method.Name);
}
}
#endregion method
Expand All @@ -626,8 +680,12 @@ internal string BaseParameterizedPropertyType(PSParameterizedProperty property)
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyType", "CatchFromBaseParameterizedPropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertytype, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyType",
"CatchFromBaseParameterizedPropertyTypeTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertytype,
property.Name);
}
}

Expand All @@ -640,8 +698,12 @@ internal bool BaseParameterizedPropertyIsSettable(PSParameterizedProperty proper
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyIsSettable", "CatchFromBaseParameterizedPropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyWriteState, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyIsSettable",
"CatchFromBaseParameterizedPropertyIsSettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyWriteState,
property.Name);
}
}

Expand All @@ -654,8 +716,12 @@ internal bool BaseParameterizedPropertyIsGettable(PSParameterizedProperty proper
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyIsGettable", "CatchFromBaseParameterizedPropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyReadState, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyIsGettable",
"CatchFromBaseParameterizedPropertyIsGettableTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyReadState,
property.Name);
}
}

Expand All @@ -668,8 +734,12 @@ internal Collection<string> BaseParameterizedPropertyDefinitions(PSParameterized
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyDefinitions", "CatchFromBaseParameterizedPropertyDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyDefinitions, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyDefinitions",
"CatchFromBaseParameterizedPropertyDefinitionsTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyDefinitions,
property.Name);
}
}

Expand All @@ -682,18 +752,22 @@ internal object BaseParameterizedPropertyGet(PSParameterizedProperty property, p
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new GetValueInvocationException("CatchFromBaseAdapterParameterizedPropertyGetValueTI",
throw new GetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertyGetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, inner.Message);
property.Name,
inner.Message);
}
catch (GetValueException) { throw; }
catch (Exception e)
{
throw new GetValueInvocationException("CatchFromBaseParameterizedPropertyAdapterGetValue",
throw new GetValueInvocationException(
"CatchFromBaseParameterizedPropertyAdapterGetValue",
e,
ExtendedTypeSystem.ExceptionWhenGetting,
property.Name, e.Message);
property.Name,
e.Message);
}
}

Expand All @@ -706,18 +780,22 @@ internal void BaseParameterizedPropertySet(PSParameterizedProperty property, obj
catch (TargetInvocationException ex)
{
Exception inner = ex.InnerException ?? ex;
throw new SetValueInvocationException("CatchFromBaseAdapterParameterizedPropertySetValueTI",
throw new SetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertySetValueTI",
inner,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, inner.Message);
property.Name,
inner.Message);
}
catch (SetValueException) { throw; }
catch (Exception e)
{
throw new SetValueInvocationException("CatchFromBaseAdapterParameterizedPropertySetValue",
throw new SetValueInvocationException(
"CatchFromBaseAdapterParameterizedPropertySetValue",
e,
ExtendedTypeSystem.ExceptionWhenSetting,
property.Name, e.Message);
property.Name,
e.Message);
}
}

Expand All @@ -730,8 +808,12 @@ internal string BaseParameterizedPropertyToString(PSParameterizedProperty proper
catch (ExtendedTypeSystemException) { throw; }
catch (Exception e)
{
throw NewException(e, "CatchFromBaseParameterizedPropertyToString", "CatchFromBaseParameterizedPropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyString, property.Name);
throw NewException(
e,
"CatchFromBaseParameterizedPropertyToString",
"CatchFromBaseParameterizedPropertyToStringTI",
ExtendedTypeSystem.ExceptionRetrievingParameterizedPropertyString,
property.Name);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/System.Management.Automation/engine/MshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,9 @@ private static void AddGenericArguments(StringBuilder sb, Type[] genericArgument
internal static string Type(Type type, bool dropNamespaces = false, string key = null)
{
if (type == null)
{
return string.Empty;
}

string result;
if (type.IsGenericType && !type.IsGenericTypeDefinition)
Expand Down
Loading