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
4 changes: 2 additions & 2 deletions .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ dotnet_diagnostic.CA2207.severity = warning

# CA2208: Instantiate argument exceptions correctly
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2208
dotnet_diagnostic.CA2208.severity = suggestion
dotnet_code_quality.CA2208.api_surface = all
dotnet_diagnostic.CA2208.severity = warning
dotnet_code_quality.ca2208.api_surface = all

# CA2211: Non-constant fields should not be visible
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2211
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ private void ProcessMTUSize(string targetNameOrAddress)
WriteObject(new PingMtuStatus(
Source,
resolvedTargetName,
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
replyResult ?? throw new ArgumentNullException(nameof(replyResult)),
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
CurrentMTUSize));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public ConsoleColorCmdlet()
private static ErrorRecord BuildOutOfRangeErrorRecord(object val, string errorId)
{
string msg = StringUtil.Format(HostStrings.InvalidColorErrorTemplate, val.ToString());
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
ArgumentOutOfRangeException e = new("value", val, msg);
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
return new ErrorRecord(e, errorId, ErrorCategory.InvalidArgument, null);
}
#endregion helper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ private List<string> ResolvePath(string path, bool isLiteral)
{
string errorMessage = StringUtil.Format(ConvertMarkdownStrings.FileSystemPathsOnly, path);
ErrorRecord errorRecord = new(
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
new ArgumentException(),
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
"OnlyFileSystemPathsSupported",
ErrorCategory.InvalidArgument,
path);
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
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,9 @@ private void SetCommandLineError(string msg, bool showHelp = false, bool showBan
{
if (_error != null)
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentException(nameof(SetCommandLineError), nameof(_error));
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}

_error = msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ internal void VerifyDataNotNull(object obj, string name)
string msg = StringUtil.Format(FormatAndOut_format_xxx.FOD_NullDataMember, name);

ErrorRecord errorRecord = new ErrorRecord(
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
new ArgumentException(),
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
"FormatObjectDeserializerNullDataMember",
ErrorCategory.InvalidData,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ public unsafe void CopyFromIndirect(object value)
break;

default:
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentException();
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,9 @@ private static List<CompletionResult> GetResultForIdentifier(CompletionContext c
case UsingStatementKind.Type:
break;
default:
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentOutOfRangeException("UsingStatementKind");
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/parser/ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5589,7 +5589,7 @@ public PipelineChainAst(

if (chainOperator != TokenKind.AndAnd && chainOperator != TokenKind.OrOr)
{
throw new ArgumentException(nameof(chainOperator));
throw new ArgumentException(null, nameof(chainOperator));
}

LhsPipelineChain = lhsChain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ internal SSHClientSessionTransportManager(
PSRemotingCryptoHelper cryptoHelper)
: base(runspaceId, cryptoHelper)
{
if (connectionInfo == null) { throw new PSArgumentException("connectionInfo"); }
if (connectionInfo == null) { throw new PSArgumentException(null, nameof(connectionInfo)); }

_connectionInfo = connectionInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ internal static IEnumerable<PropertyInfo> GetAccessProperties(Type tupleType, in
{
// ContractUtils.RequiresNotNull(tupleType, "tupleType");

if (index < 0 || index >= size) throw new ArgumentException("index");
if (index < 0 || index >= size) throw new ArgumentException(null, nameof(index));

foreach (int curIndex in GetAccessPath(size, index))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6699,7 +6699,9 @@ public IContentReader GetContentReader(string path)
if (usingByteEncoding)
{
Exception e =
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
new ArgumentException(FileSystemProviderStrings.DelimiterError, "delimiter");
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
WriteError(new ErrorRecord(
e,
"GetContentReaderArgumentError",
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/MshTraceSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal static PSTraceSource GetNewTraceSource(
// Note, all callers should have already verified the name before calling this
// API, so this exception should never be exposed to an end-user.

throw new ArgumentException("name");
throw new ArgumentException(null, nameof(name));
}

// Keep the fullName as it was passed, but truncate or pad
Expand Down
2 changes: 2 additions & 0 deletions src/TypeCatalogGen/TypeCatalogGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ private static string ResolveTargetFilePath(string path)
{
if (string.IsNullOrWhiteSpace(path))
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentNullException(Param_TargetCSharpFilePath);
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}

string targetPath = Path.GetFullPath(path);
Expand Down
4 changes: 4 additions & 0 deletions src/powershell/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private static void AttemptExecPwshLogin(string[] args)

if (pwshPath == null)
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentNullException(nameof(pwshPath));
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}

// exec pwsh
Expand Down Expand Up @@ -209,7 +211,9 @@ private static void AttemptExecPwshLogin(string[] args)

if (pwshPath == null)
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentNullException(nameof(pwshPath));
#pragma warning restore CA2208 // https://github.com/PowerShell/PowerShell/issues/13909
}

// exec pwsh
Expand Down