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

Fix formatting of resource string where excess arguments are passed #63824

Merged
merged 6 commits into from
Jan 25, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Namespace Microsoft.VisualBasic.FileIO
Public Function PeekChars(ByVal numberOfChars As Integer) As String

If numberOfChars <= 0 Then
Throw GetArgumentExceptionWithArgName("numberOfChars", SR.TextFieldParser_NumberOfCharsMustBePositive, "numberOfChars")
Throw GetArgumentExceptionWithArgName("numberOfChars", SR.TextFieldParser_NumberOfCharsMustBePositive)
End If

If m_Reader Is Nothing Or m_Buffer Is Nothing Then
Expand Down Expand Up @@ -1151,7 +1151,7 @@ Namespace Microsoft.VisualBasic.FileIO
Dim Bound As Integer = Widths.Length - 1
For i As Integer = 0 To Bound - 1
If Widths(i) < 1 Then
Throw GetArgumentExceptionWithArgName("FieldWidths", SR.TextFieldParser_FieldWidthsMustPositive, "FieldWidths")
Throw GetArgumentExceptionWithArgName("FieldWidths", SR.TextFieldParser_FieldWidthsMustPositive)
End If
Next
End Sub
Expand All @@ -1163,11 +1163,11 @@ Namespace Microsoft.VisualBasic.FileIO
''' <remarks></remarks>
Private Sub ValidateAndEscapeDelimiters()
If m_Delimiters Is Nothing Then
Throw GetArgumentExceptionWithArgName("Delimiters", SR.TextFieldParser_DelimitersNothing, "Delimiters")
Throw GetArgumentExceptionWithArgName("Delimiters", SR.TextFieldParser_DelimitersNothing)
End If

If m_Delimiters.Length = 0 Then
Throw GetArgumentExceptionWithArgName("Delimiters", SR.TextFieldParser_DelimitersNothing, "Delimiters")
Throw GetArgumentExceptionWithArgName("Delimiters", SR.TextFieldParser_DelimitersNothing)
End If

Dim Length As Integer = m_Delimiters.Length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subK
return baseKey;
}

throw new ArgumentException(SR.Format(SR.Arg_RegInvalidKeyName, nameof(keyName)), nameof(keyName));
throw new ArgumentException(SR.Arg_RegInvalidKeyName, nameof(keyName));
danmoseley marked this conversation as resolved.
Show resolved Hide resolved
}

public static object? GetValue(string keyName, string? valueName, object? defaultValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed partial class RegistrySecurity : NativeObjectSecurity
break;

case Interop.Errors.ERROR_INVALID_NAME:
exception = new ArgumentException(SR.Format(SR.Arg_RegInvalidKeyName, nameof(name)));
exception = new ArgumentException(SR.Arg_RegInvalidKeyName, nameof(name));
break;

case Interop.Errors.ERROR_INVALID_HANDLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina

if (values.Length != 4)
{
throw new ArgumentException(SR.Format(SR.TextParseFailedFormat, "text", text, "x, y, width, height"));
throw new ArgumentException(SR.Format(SR.TextParseFailedFormat, text, "x, y, width, height"));
}

return new Rectangle(values[0], values[1], values[2], values[3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public void Test_GenerateManifest_InvalidEventSources()
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty));
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId"), e);

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId"), e);

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId"), e);

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => string.Join(Environment.NewLine,
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Test_GenerateManifest_InvalidEventSources()

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => string.Join(Environment.NewLine,
GetResourceString("EventSource_EnumKindMismatch", "Op1", "EventKeywords", "Opcodes"),
GetResourceString("EventSource_EnumKindMismatch", "EventKeywords", "Opcodes"),
GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger")),
e);

Expand All @@ -144,14 +144,14 @@ public void Test_GenerateManifest_InvalidEventSources()

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => string.Join(Environment.NewLine,
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1),
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
e);


e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => string.Join(Environment.NewLine,
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1),
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
}
else {
throw new ArgumentException(SR.Format(SR.TextParseFailedFormat,
"text",
text,
"x, y, width, height"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public virtual ulong CurrentSize
{
get
{
throw new InvalidOperationException(SR.Format(SR.IsolatedStorage_CurrentSizeUndefined, nameof(CurrentSize)));
throw new InvalidOperationException(SR.IsolatedStorage_CurrentSizeUndefined);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.IO.Packaging/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<value>Invalid file format.</value>
</data>
<data name="FileFormatExceptionWithFileName" xml:space="preserve">
<value>Invalid file format.</value>
<value>File '{0}' has an invalid file format.</value>
</data>
<data name="GetContentTypeCoreNotImplemented" xml:space="preserve">
<value>PackagePart subclass must implement GetContentTypeCore method if passing a null value for the content type when PackagePart object is constructed.</value>
Expand Down Expand Up @@ -375,4 +375,4 @@
<data name="FileContainsCorruptedData" xml:space="preserve">
<value>File contains corrupted data.</value>
</data>
</root>
</root>
6 changes: 3 additions & 3 deletions src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static IPHostEntry GetHostEntry(IPAddress address)
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(address, $"Invalid address '{address}'");
throw new ArgumentException(SR.Format(SR.net_invalid_ip_addr, nameof(address)));
throw new ArgumentException(SR.net_invalid_ip_addr, nameof(address));
}

IPHostEntry ipHostEntry = GetHostEntryCore(address, AddressFamily.Unspecified);
Expand Down Expand Up @@ -81,7 +81,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(address, $"Invalid address '{address}'");
throw new ArgumentException(SR.Format(SR.net_invalid_ip_addr, nameof(hostNameOrAddress)));
throw new ArgumentException(SR.net_invalid_ip_addr, nameof(hostNameOrAddress));
}

ipHostEntry = GetHostEntryCore(address, family);
Expand Down Expand Up @@ -207,7 +207,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami
if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(address, $"Invalid address '{address}'");
throw new ArgumentException(SR.Format(SR.net_invalid_ip_addr, nameof(hostNameOrAddress)));
throw new ArgumentException(SR.net_invalid_ip_addr, nameof(hostNameOrAddress));
}

addresses = (family == AddressFamily.Unspecified || address.AddressFamily == family) ? new IPAddress[] { address } : Array.Empty<IPAddress>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public IList<ArraySegment<byte>>? BufferList
if (!_buffer.Equals(default))
{
// Can't have both set
throw new ArgumentException(SR.Format(SR.net_ambiguousbuffers, nameof(Buffer)));
throw new ArgumentException(SR.net_ambiguousbuffers);
}

// Copy the user-provided list into our internal buffer list,
Expand Down Expand Up @@ -358,7 +358,7 @@ public void SetBuffer(byte[]? buffer, int offset, int count)
// Can't have both Buffer and BufferList.
if (_bufferList != null)
{
throw new ArgumentException(SR.Format(SR.net_ambiguousbuffers, nameof(BufferList)));
throw new ArgumentException(SR.net_ambiguousbuffers);
}

// Offset and count can't be negative and the
Expand Down Expand Up @@ -391,7 +391,7 @@ public void SetBuffer(Memory<byte> buffer)
{
if (buffer.Length != 0 && _bufferList != null)
{
throw new ArgumentException(SR.Format(SR.net_ambiguousbuffers, nameof(BufferList)));
throw new ArgumentException(SR.net_ambiguousbuffers);
}

_buffer = buffer;
Expand Down Expand Up @@ -559,7 +559,7 @@ internal void StartOperationAccept()
// Caller specified a buffer - see if it is large enough
if (_count < _acceptAddressBufferCount)
{
throw new ArgumentException(SR.Format(SR.net_buffercounttoosmall, nameof(Count)));
throw new ArgumentException(SR.net_buffercounttoosmall, nameof(Count));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public Hashtable(int capacity, float loadFactor)
if (capacity < 0)
throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_NeedNonNegNum);
if (!(loadFactor >= 0.1f && loadFactor <= 1.0f))
throw new ArgumentOutOfRangeException(nameof(loadFactor), SR.Format(SR.ArgumentOutOfRange_HashtableLoadFactor, .1, 1.0));
throw new ArgumentOutOfRangeException(nameof(loadFactor), SR.ArgumentOutOfRange_HashtableLoadFactor);

// Based on perf work, .72 is the optimal load factor for this table.
_loadFactor = 0.72f * loadFactor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3280,7 +3280,7 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt
}
else if (eventAttribute.EventId <= 0)
{
manifest.ManifestError(SR.Format(SR.EventSource_NeedPositiveId, method.Name), true);
manifest.ManifestError(SR.EventSource_NeedPositiveId, true);
continue; // don't validate anything else for this event
}
if (method.Name.LastIndexOf('.') >= 0)
Expand Down Expand Up @@ -3501,7 +3501,7 @@ private static void AddProviderEnumKind(ManifestBuilder manifest, FieldInfo stat
#endif
return;
Error:
manifest.ManifestError(SR.Format(SR.EventSource_EnumKindMismatch, staticField.Name, staticField.FieldType.Name, providerEnumKind));
manifest.ManifestError(SR.Format(SR.EventSource_EnumKindMismatch, staticField.FieldType.Name, providerEnumKind));
danmoseley marked this conversation as resolved.
Show resolved Hide resolved
}

// Helper used by code:CreateManifestAndDescriptors to add a code:EventData descriptor for a method
Expand Down Expand Up @@ -3630,7 +3630,7 @@ private static void DebugCheckEvent(ref Dictionary<string, string>? eventsByName

if (evtId < eventData.Length && eventData[evtId].Descriptor.EventId != 0)
{
manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId, eventData[evtId].Name), true);
manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId), true);
}

// We give a task to things if they don't have one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void Read<T>(long position, out T structure) where T : struct
}
else
{
throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToRead, typeof(T)), nameof(position));
throw new ArgumentException(SR.Argument_NotEnoughBytesToRead, nameof(position));
}
}

Expand Down Expand Up @@ -561,7 +561,7 @@ public void Write<T>(long position, ref T structure) where T : struct
}
else
{
throw new ArgumentException(SR.Format(SR.Argument_NotEnoughBytesToWrite, typeof(T)), nameof(position));
throw new ArgumentException(SR.Argument_NotEnoughBytesToWrite, nameof(position));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Private.CoreLib/src/System/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected virtual double Sample()
}

private static void ThrowMaxValueMustBeNonNegative() =>
throw new ArgumentOutOfRangeException("maxValue", SR.Format(SR.ArgumentOutOfRange_NeedNonNegNum, "maxValue"));
throw new ArgumentOutOfRangeException("maxValue", SR.ArgumentOutOfRange_NeedNonNegNum);

private static void ThrowMinMaxValueSwapped() =>
throw new ArgumentOutOfRangeException("minValue", SR.Format(SR.Argument_MinMaxValue, "minValue", "maxValue"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public DecoderReplacementFallback(string replacement)
break;
}
if (bFoundHigh)
throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement));

_strDefault = replacement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public EncoderReplacementFallback(string replacement)
break;
}
if (bFoundHigh)
throw new ArgumentException(SR.Format(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement)));
throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(replacement));

_strDefault = replacement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ public void LoadGeneric12(InputType inputType, ReaderType readerType, TransformT
}
catch (System.InvalidOperationException e2)
{
CheckExpectedError(e2, "system.xml", "Xslt_NoStylesheetLoaded", new string[] { "IDontExist.xsl" });
CheckExpectedError(e2, "system.xml", "Xslt_NoStylesheetLoaded", new string[] { "" });
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public string GetDocumentName(DocumentNameBlobHandle handle)
int separator = blobReader.ReadByte();
if (separator > 0x7f)
{
throw new BadImageFormatException(SR.Format(SR.InvalidDocumentName, separator));
throw new BadImageFormatException(SR.InvalidDocumentName);
}

var pooledBuilder = PooledStringBuilder.GetInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ internal static bool TryValidateParseStyleInteger(NumberStyles style, [NotNullWh
// Check for undefined flags
if ((style & InvalidNumberStyles) != 0)
{
e = new ArgumentException(SR.Format(SR.Argument_InvalidNumberStyles, nameof(style)));
e = new ArgumentException(SR.Argument_InvalidNumberStyles, nameof(style));
return false;
}
if ((style & NumberStyles.AllowHexSpecifier) != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<value>The specified curve '{0}' or its parameters are not valid for this platform.</value>
</data>
<data name="Cryptography_InvalidCurveOid" xml:space="preserve">
<value>The specified Oid is not valid. The Oid.FriendlyName or Oid.Value property must be set.</value>
<value>The specified Oid ({0}) is not valid. The Oid.FriendlyName or Oid.Value property must be set.</value>
</data>
<data name="Cryptography_InvalidIVSize" xml:space="preserve">
<value>Specified initialization vector (IV) does not match the block size for this algorithm.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public string UniqueKeyContainerName
{
if (throwOnNotFound)
{
throw new CryptographicException(SR.Format(SR.Cryptography_CSP_NotFound, "Error"));
throw new CryptographicException(SR.Cryptography_CSP_NotFound);
}

return null;
Expand Down Expand Up @@ -243,7 +243,7 @@ private object ReadDeviceParameterVerifyContext(int keyParam)
{
if (hr != CapiHelper.S_OK)
{
throw new CryptographicException(SR.Format(SR.Cryptography_CSP_NotFound, "Error"));
throw new CryptographicException(SR.Cryptography_CSP_NotFound);
}

object retVal = CapiHelper.GetProviderParameter(safeProvHandle, parameters.KeyNumber, keyParam);
Expand Down
Loading