From f4834fc3aaec0722849a0711527929de09e1e791 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 01:45:43 +0000 Subject: [PATCH] Fix CA2208 warnings across the project This commit resolves `CA2208` (Instantiate argument exceptions correctly) warnings by ensuring `ArgumentException` and `ArgumentOutOfRangeException` are instantiated correctly. Specifically: - In `OccursExtension.cs` and `RepresentationExtension.cs`, empty `ArgumentException` calls were replaced with ones that include a specific error message and the `nameof()` parameter name. - In `OslcRdfOutputFormatter.cs` and `OslcRdfInputFormatter.cs`, instances where `ArgumentOutOfRangeException` was inappropriately using a local variable (`requestedType`) as the `paramName` were changed to throw a `NotSupportedException` since `requestedType` is derived from an object's state and is not a method parameter. All changes have been successfully compiled without triggering the CA2208 rule. `dotnet format style` was run before submitting. Co-authored-by: berezovskyi <64734+berezovskyi@users.noreply.github.com> --- OSLC4Net_SDK/OSLC4Net.Core/Model/OccursExtension.cs | 2 +- OSLC4Net_SDK/OSLC4Net.Core/Model/RepresentationExtension.cs | 2 +- .../OSLC4Net.Server.Providers/OslcRdfInputFormatter.cs | 3 +-- .../OSLC4Net.Server.Providers/OslcRdfOutputFormatter.cs | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/OSLC4Net_SDK/OSLC4Net.Core/Model/OccursExtension.cs b/OSLC4Net_SDK/OSLC4Net.Core/Model/OccursExtension.cs index b45d88a5..ad7c89ff 100644 --- a/OSLC4Net_SDK/OSLC4Net.Core/Model/OccursExtension.cs +++ b/OSLC4Net_SDK/OSLC4Net.Core/Model/OccursExtension.cs @@ -32,7 +32,7 @@ public static Occurs FromString(string value) } } - throw new ArgumentException(); + throw new ArgumentException($"Invalid string representation of Occurs value: {value}", nameof(value)); } public static Occurs FromURI(URI uri) diff --git a/OSLC4Net_SDK/OSLC4Net.Core/Model/RepresentationExtension.cs b/OSLC4Net_SDK/OSLC4Net.Core/Model/RepresentationExtension.cs index d83f2b56..e1e83629 100644 --- a/OSLC4Net_SDK/OSLC4Net.Core/Model/RepresentationExtension.cs +++ b/OSLC4Net_SDK/OSLC4Net.Core/Model/RepresentationExtension.cs @@ -32,7 +32,7 @@ public static Representation FromString(string value) } } - throw new ArgumentException(); + throw new ArgumentException($"Invalid string representation of Representation value: {value}", nameof(value)); } public static Representation FromURI(URI uri) diff --git a/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfInputFormatter.cs b/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfInputFormatter.cs index 92fece80..5699341a 100644 --- a/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfInputFormatter.cs +++ b/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfInputFormatter.cs @@ -48,8 +48,7 @@ public override async Task ReadRequestBodyAsync( OslcMediaType.TEXT_TURTLE => RdfFormat.Turtle, OslcMediaType.APPLICATION_NTRIPLES => RdfFormat.NTriples, OslcMediaType.APPLICATION_JSON_LD => RdfFormat.JsonLd, - _ => throw new ArgumentOutOfRangeException(nameof(requestedType), - "Unknown RDF format"), + _ => throw new NotSupportedException($"Unknown RDF format: {requestedType}"), }; using var reader = new StreamReader(context.HttpContext.Request.Body, encoding); diff --git a/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfOutputFormatter.cs b/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfOutputFormatter.cs index a6cfbb14..159bdc73 100644 --- a/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfOutputFormatter.cs +++ b/OSLC4Net_SDK/OSLC4Net.Server.Providers/OslcRdfOutputFormatter.cs @@ -61,8 +61,7 @@ public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext co OslcMediaType.TEXT_TURTLE => RdfFormat.Turtle, OslcMediaType.APPLICATION_NTRIPLES => RdfFormat.NTriples, OslcMediaType.APPLICATION_JSON_LD => RdfFormat.JsonLd, - _ => throw new ArgumentOutOfRangeException(nameof(requestedType), - "Unknown RDF format"), + _ => throw new NotSupportedException($"Unknown RDF format: {requestedType}"), }, Graph = graph };