Frends.JSON.Query: fix compliance findings (net8, static class, CancellationToken, error handling) - #40
Frends.JSON.Query: fix compliance findings (net8, static class, CancellationToken, error handling)#40MichalFrends1 with Copilot wants to merge 4 commits into
Conversation
…lationToken, error handling, csproj properties
| { | ||
| throw; | ||
| } | ||
| catch (Exception ex) |
There was a problem hiding this comment.
@copilot use Result Handle method that was provided in initial prompt instead this code in main method for error handler options. You can also remove newly added constructor with error and add error filed to current constructor, or remove both constructors if they are not needed.
There was a problem hiding this comment.
Done in the latest commit. The inline error handling has been extracted into a new Helpers/ErrorHandler.cs following the standard Handle extension method pattern. Query.cs now simply calls ex.Handle(options) in the catch block, and the success path uses an object initializer. Both Result constructors were removed — all three properties now use internal set, which is what allows ErrorHandler to use the object initializer syntax.
| [TestMethod] | ||
| public void QueryShouldReturnErrorResultWhenThrowErrorOnFailureIsFalse() | ||
| { | ||
| var input = new Input() | ||
| { | ||
| Json = jsonString, | ||
| Query = "$..Products[?(@.Price >= 1000)].Name" | ||
| }; | ||
|
|
||
| var options = new Options() | ||
| { | ||
| ErrorWhenNotMatched = true, | ||
| ThrowErrorOnFailure = false, | ||
| }; | ||
|
|
||
| var result = JSON.Query(input, options, CancellationToken.None); | ||
| Assert.IsFalse(result.Success); | ||
| Assert.IsNotNull(result.Error); | ||
| Assert.IsFalse(string.IsNullOrEmpty(result.Error.Message)); | ||
| Assert.IsNotNull(result.Error.AdditionalInfo); |
There was a problem hiding this comment.
@copliot instead of this test please create new error handler class same like this one: https://github.com/FrendsPlatform/Frends.Smb/blob/main/Frends.Smb.WriteFile/Frends.Smb.WriteFile.Tests/ErrorHandlerTest.cs
Resolves five task-analyzer findings (FT0004, FT0007, FT0011, FT0015 ×2) plus csproj compliance gaps in
Frends.JSON.Query. Bumps target framework to net8 and version to 1.3.0.csproj
Frends.JSON.Query.csproj:net6.0→net8.0, version1.2.0→1.3.0Frends.JSON.Query.UnitTests.csproj:net6.0→net8.0, added<PackageProjectUrl>and<Product>Frends</Product>(theUnitTestssuffix is not matched by the*.Test*.csprojexclude pattern)Definitions
Options: addedThrowErrorOnFailure(bool, defaulttrue) andErrorMessageOnFailure(string, default"") — FT0015Error(new):Message+AdditionalInfo(Exception)Result: addedErrorproperty; added internal constructor for the failure path — FT0011Task class (
Query.cs)JSONmadestatic— FT0004Querygains aCancellationTokenparameter — FT0007OperationCanceledExceptionis always rethrownThrowErrorOnFailure = true(default, preserves existing behaviour); returned asResult { Success=false, Error=… }whenfalseTests
CancellationToken.NoneQueryShouldThrowIfOptionSetAndFilterMatchesNothingupdated to assertException(error handler wraps the originalJsonException)QueryShouldReturnErrorResultWhenThrowErrorOnFailureIsFalse