Skip to content

Frends.JSON.Query: fix compliance findings (net8, static class, CancellationToken, error handling) - #40

Open
MichalFrends1 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-compliance-findings-frends-json-query
Open

Frends.JSON.Query: fix compliance findings (net8, static class, CancellationToken, error handling)#40
MichalFrends1 with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-compliance-findings-frends-json-query

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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.0net8.0, version 1.2.01.3.0
  • Frends.JSON.Query.UnitTests.csproj: net6.0net8.0, added <PackageProjectUrl> and <Product>Frends</Product> (the UnitTests suffix is not matched by the *.Test*.csproj exclude pattern)

Definitions

  • Options: added ThrowErrorOnFailure (bool, default true) and ErrorMessageOnFailure (string, default "") — FT0015
  • Error (new): Message + AdditionalInfo (Exception)
  • Result: added Error property; added internal constructor for the failure path — FT0011

Task class (Query.cs)

  • JSON made static — FT0004
  • Query gains a CancellationToken parameter — FT0007
  • Method body wrapped in try/catch following the standard ErrorHandler pattern:
    • OperationCanceledException is always rethrown
    • Other exceptions: thrown (wrapped) when ThrowErrorOnFailure = true (default, preserves existing behaviour); returned as Result { Success=false, Error=… } when false
// New signature
public static Result Query(
    [PropertyTab] Input input,
    [PropertyTab] Options options,
    CancellationToken cancellationToken)

// Non-throwing path
var options = new Options { ThrowErrorOnFailure = false };
var result = JSON.Query(input, options, cancellationToken);
// result.Success == false, result.Error.Message populated

Tests

  • Existing calls updated with CancellationToken.None
  • QueryShouldThrowIfOptionSetAndFilterMatchesNothing updated to assert Exception (error handler wraps the original JsonException)
  • Added QueryShouldReturnErrorResultWhenThrowErrorOnFailureIsFalse

…lationToken, error handling, csproj properties
Copilot AI changed the title [WIP] Fix compliance findings in Frends.JSON.Query Frends.JSON.Query: fix compliance findings (net8, static class, CancellationToken, error handling) Jul 31, 2026
Copilot AI requested a review from MichalFrends1 July 31, 2026 09:44
{
throw;
}
catch (Exception ex)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +121 to +140
[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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot AI requested a review from MichalFrends1 August 3, 2026 08:32
@MichalFrends1
MichalFrends1 marked this pull request as ready for review August 3, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants