Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected TSession[] Session
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

_session = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ private void ThrowMinGreaterThanOrEqualMax(object minValue, object maxValue)
{
if (minValue == null)
{
throw PSTraceSource.NewArgumentNullException("min");
throw PSTraceSource.NewArgumentNullException(nameof(minValue));
}

if (maxValue == null)
{
throw PSTraceSource.NewArgumentNullException("max");
throw PSTraceSource.NewArgumentNullException(nameof(maxValue));
}

ErrorRecord errorRecord = new ErrorRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public void CopyTo(T[] array, int arrayIndex)

if (Count > (array.Length - arrayIndex))
{
throw new ArgumentException("arrayIndex");
throw new ArgumentException(null, nameof(arrayIndex));
}

// Iterate through the buffer in correct order.
Expand Down Expand Up @@ -1312,7 +1312,7 @@ public string[] Exclude
{
// null check is not needed (because of ValidateNotNullOrEmpty),
// but we have to include it to silence OACR
_excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException("value");
_excludeStrings = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value));

_exclude = new WildcardPattern[_excludeStrings.Length];
for (int i = 0; i < _excludeStrings.Length; i++)
Expand Down Expand Up @@ -1370,7 +1370,7 @@ public string[] Exclude
{
// null check is not needed (because of ValidateNotNullOrEmpty),
// but we have to include it to silence OACR
_context = value ?? throw PSTraceSource.NewArgumentNullException("value");
_context = value ?? throw PSTraceSource.NewArgumentNullException(nameof(value));

if (_context.Length == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ private void AddMultipartContent(object fieldName, object fieldValue, MultipartF
{
if (formData == null)
{
throw new ArgumentNullException("formDate");
throw new ArgumentNullException(nameof(formData));
}

// It is possible that the dictionary keys or values are PSObject wrapped depending on how the dictionary is defined and assigned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override
}
else
{
throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
}
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public override
}
else
{
throw PSTraceSource.NewArgumentException("value", ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
throw PSTraceSource.NewArgumentException(nameof(value), ConsoleHostRawUserInterfaceStrings.InvalidConsoleColorError);
}
}
}
Expand Down Expand Up @@ -844,7 +844,7 @@ public override string WindowTitle
}
else
{
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentNullException(nameof(value));
}
}
}
Expand Down Expand Up @@ -1218,22 +1218,22 @@ int LengthInBufferCells(string s)
/// <summary>
/// See base class.
/// </summary>
/// <param name="s"></param>
/// <param name="str"></param>
/// <param name="offset"></param>
/// <returns></returns>
/// <exception cref="HostException">
/// If Win32's WideCharToMultiByte fails
/// </exception>

public override
int LengthInBufferCells(string s, int offset)
int LengthInBufferCells(string str, int offset)
{
if (s == null)
if (str == null)
{
throw PSTraceSource.NewArgumentNullException("str");
throw PSTraceSource.NewArgumentNullException(nameof(str));
}

return ConsoleControl.LengthInBufferCells(s, offset, parent.SupportsVirtualTerminal);
return ConsoleControl.LengthInBufferCells(str, offset, parent.SupportsVirtualTerminal);
Comment on lines +1221 to +1236
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep different changes in different PRs

}

/// <summary>
Expand Down Expand Up @@ -1622,7 +1622,7 @@ public override void SetBufferContents(Coordinates origin,
// if there are no contents, there is nothing to set the buffer to
if (contents == null)
{
PSTraceSource.NewArgumentNullException("contents");
PSTraceSource.NewArgumentNullException(nameof(contents));
}
// if the cursor is on the last line, we need to make more space to print the specified buffer
if (origin.Y == BufferSize.Height - 1 && origin.X >= BufferSize.Width)
Expand Down Expand Up @@ -1695,19 +1695,19 @@ int LengthInBufferCells(string s)
/// <summary>
/// See base class.
/// </summary>
/// <param name="s"></param>
/// <param name="str"></param>
/// <param name="offset"></param>
/// <returns></returns>

public override
int LengthInBufferCells(string s, int offset)
int LengthInBufferCells(string str, int offset)
{
if (s == null)
if (str == null)
{
throw PSTraceSource.NewArgumentNullException("str");
throw PSTraceSource.NewArgumentNullException(nameof(str));
}

return ConsoleControl.LengthInBufferCells(s, offset, _parent.SupportsVirtualTerminal);
return ConsoleControl.LengthInBufferCells(str, offset, _parent.SupportsVirtualTerminal);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.WSMan.Management/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ protected override void SetItem(string path, object value)
{
if (value == null)
{
throw new ArgumentException(helper.GetResourceMsgFromResourcetext("value"));
throw new ArgumentException(helper.GetResourceMsgFromResourcetext(nameof(value)));
}

string ChildName = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ private static void LoadPowerShellClassResourcesFromModule(PSModuleInfo primaryM
if (moduleInfo.ModuleType == ModuleType.Binary)
{
#if CORECLR
throw PSTraceSource.NewArgumentException("isConfiguration", ParserStrings.ConfigurationNotSupportedInPowerShellCore);
throw PSTraceSource.NewArgumentException(nameof(moduleInfo), ParserStrings.ConfigurationNotSupportedInPowerShellCore);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right

#else
ResolveEventHandler reh = (sender, args) => CurrentDomain_ReflectionOnlyAssemblyResolve(sender, args, moduleInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private void ProcessPayload(FormatEntryData fed, FormatMessagesContextManager.Ou

if (fed.formatEntryInfo == null)
{
PSTraceSource.NewArgumentNullException("fed.formatEntryInfo");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why do we change this? Please revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not use ArgumentNullException here as the argument is not null but a property.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intention is to trace. We shouldn't remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we do not throw the exception from NewArgumentNullException here. I think this could be a bug.

PSTraceSource.NewArgumentException(nameof(fed), "fed.formatEntryInfo is null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move any changes which change an exception type to a new PR

}

WriteStreamType oldWSState = _lo.WriteStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ internal DisplayEntry(ExpressionToken expression)

if (string.IsNullOrEmpty(Value))
if (Value == null || ValueType == DisplayEntryValueType.Property)
throw PSTraceSource.NewArgumentNullException("value");
throw PSTraceSource.NewArgumentException(nameof(expression));
}

internal bool SafeForExport()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ internal TableControl(TableControlBody tcb, ViewDefinition viewDefinition) : thi
public TableControl(TableControlRow tableControlRow) : this()
{
if (tableControlRow == null)
throw PSTraceSource.NewArgumentNullException("tableControlRows");
throw PSTraceSource.NewArgumentNullException(nameof(tableControlRow));

this.Rows.Add(tableControlRow);
}
Expand All @@ -304,7 +304,7 @@ public TableControl(TableControlRow tableControlRow) : this()
public TableControl(TableControlRow tableControlRow, IEnumerable<TableControlColumnHeader> tableControlColumnHeaders) : this()
{
if (tableControlRow == null)
throw PSTraceSource.NewArgumentNullException("tableControlRows");
throw PSTraceSource.NewArgumentNullException(nameof(tableControlRow));
if (tableControlColumnHeaders == null)
throw PSTraceSource.NewArgumentNullException(nameof(tableControlColumnHeaders));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private void LoadData(XmlDocument doc, TypeInfoDataBase db)
private void LoadData(ExtendedTypeDefinition typeDefinition, TypeInfoDataBase db, bool isForHelpOutput)
{
if (typeDefinition == null)
throw PSTraceSource.NewArgumentNullException("viewDefinition");
throw PSTraceSource.NewArgumentNullException(nameof(typeDefinition));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, why is this changed


if (db == null)
throw PSTraceSource.NewArgumentNullException(nameof(db));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ internal static FormatInfoData CreateInstance(PSObject so, FormatObjectDeseriali
string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_InvalidClassidProperty);

ErrorRecord errorRecord = new ErrorRecord(
PSTraceSource.NewArgumentException("classid"),
PSTraceSource.NewArgumentException(nameof(classId)),
"FormatObjectDeserializerInvalidClassidProperty",
ErrorCategory.InvalidData,
so);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ internal CmdletInfo AddCmdletInfoToCache(string name, CmdletInfo newCmdletInfo,

if (newCmdletInfo == null)
{
throw PSTraceSource.NewArgumentNullException("cmdlet");
throw PSTraceSource.NewArgumentNullException(nameof(newCmdletInfo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

}

if (isGlobal)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/FunctionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ internal void Update(ScriptBlock newFunction, bool force, ScopedItemOptions opti
{
if (newFunction == null)
{
throw PSTraceSource.NewArgumentNullException("function");
throw PSTraceSource.NewArgumentNullException(nameof(newFunction));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

}

if ((_options & ScopedItemOptions.Constant) != 0)
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public string[] ParameterName
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

_parameterNames = value;
Expand Down Expand Up @@ -316,7 +316,7 @@ public PSTypeName[] ParameterType
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

// if '...CimInstance#Win32_Process' is specified, then exclude '...CimInstance'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,7 @@ private void DoWriteError(object obj)
ActionPreference preference = pair.Value;
if (errorRecord == null)
{
throw PSTraceSource.NewArgumentNullException("errorRecord");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not NewArgumentNullException(nameof(errorRecord))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method signature is DoWriteError(object obj), errorRecord is not an argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intention is to trace. We shouldn't remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not pass "errorRecord" as paramName as it is not an argument for this method.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is not for the style PR.

throw PSTraceSource.NewArgumentException(nameof(obj), "errorRecord is null");
}

// If this error came from a transacted cmdlet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private PSSnapinQualifiedName(string[] splitName)
// Since the provider name contained multiple slashes it is
// a bad format.

throw PSTraceSource.NewArgumentException("name");
throw PSTraceSource.NewArgumentException(nameof(splitName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

}

// Now set the full name
Expand Down
14 changes: 7 additions & 7 deletions src/System.Management.Automation/engine/ProgressRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ class ProgressRecord
{
// negative Ids are reserved to indicate "no id" for parent Ids.

throw PSTraceSource.NewArgumentOutOfRangeException(nameof(activityId), activityId, ProgressRecordStrings.ArgMayNotBeNegative, "activityId");
throw PSTraceSource.NewArgumentOutOfRangeException(nameof(activityId), activityId, ProgressRecordStrings.ArgMayNotBeNegative, nameof(activityId));
}

if (string.IsNullOrEmpty(activity))
{
throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "activity");
throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(activity));
}

if (string.IsNullOrEmpty(statusDescription))
{
throw PSTraceSource.NewArgumentException(nameof(activity), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "statusDescription");
throw PSTraceSource.NewArgumentException(nameof(statusDescription), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(statusDescription));
}

this.id = activityId;
Expand Down Expand Up @@ -121,7 +121,7 @@ internal ProgressRecord(ProgressRecord other)
{
if (value == ActivityId)
{
throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ParentActivityIdCantBeActivityId);
throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ParentActivityIdCantBeActivityId);
}

parentId = value;
Expand Down Expand Up @@ -149,7 +149,7 @@ internal ProgressRecord(ProgressRecord other)
{
if (string.IsNullOrEmpty(value))
{
throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "value");
throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(value));
}

activity = value;
Expand All @@ -173,7 +173,7 @@ internal ProgressRecord(ProgressRecord other)
{
if (string.IsNullOrEmpty(value))
{
throw PSTraceSource.NewArgumentException("value", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "value");
throw PSTraceSource.NewArgumentException(nameof(value), ProgressRecordStrings.ArgMayNotBeNullOrEmpty, nameof(value));
}

status = value;
Expand Down Expand Up @@ -276,7 +276,7 @@ internal ProgressRecord(ProgressRecord other)
{
if (value != ProgressRecordType.Completed && value != ProgressRecordType.Processing)
{
throw PSTraceSource.NewArgumentException("value");
throw PSTraceSource.NewArgumentException(nameof(value));
}

type = value;
Expand Down
Loading