From 7feba5d628a5f0114b3ec04ce8bc82a16922f6f6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 06:54:30 +0000 Subject: [PATCH 1/2] Fix ErrorWhenNotMatched not throwing for filter queries with no matches in QuerySingle --- Frends.JSON.QuerySingle/CHANGELOG.md | 4 ++++ .../UnitTests.cs | 17 +++++++++++++++++ .../Frends.JSON.QuerySingle.csproj | 2 +- .../Frends.JSON.QuerySingle/QuerySingle.cs | 8 +++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Frends.JSON.QuerySingle/CHANGELOG.md b/Frends.JSON.QuerySingle/CHANGELOG.md index d4206a0..31a4240 100644 --- a/Frends.JSON.QuerySingle/CHANGELOG.md +++ b/Frends.JSON.QuerySingle/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.3.0] - 2026-07-08 +### Fixed +- Fixed issue where Options.ErrorWhenNotMatched did not throw an exception when a JSONPath filter expression (e.g. `[?(...)]`) matched no results. + ## [1.2.0] - 2024-11-07 ### Fixed - Fixed issue with result dotnotation by changing the result Data object type to dynamic. diff --git a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.UnitTests/UnitTests.cs b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.UnitTests/UnitTests.cs index 86c569f..4182421 100644 --- a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.UnitTests/UnitTests.cs +++ b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.UnitTests/UnitTests.cs @@ -77,6 +77,23 @@ public void QueryShouldThrowIfOptionSetAndNothingIsFound() Assert.IsTrue(ex.Message.Contains("Property 'Manufacturer' does not exist on JObject.")); } + [TestMethod] + public void QuerySingleShouldThrowIfOptionSetAndFilterMatchesNothing() + { + var input = new Input() + { + Json = jsonString, + Query = "$.Manufacturers[?(@.Name == 'Nonexistent Co')]" + }; + + var options = new Options() + { + ErrorWhenNotMatched = true, + }; + + Assert.ThrowsException(() => JSON.QuerySingle(input, options)); + } + [TestMethod] public void QuerySingleShouldNotThrowIfOptionNotSetAndNothingIsFound() { diff --git a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.csproj b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.csproj index 19ca6b1..0f8f7b2 100644 --- a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.csproj +++ b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle.csproj @@ -2,7 +2,7 @@ net6.0 - 1.2.0 + 1.3.0 Frends Frends Frends diff --git a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/QuerySingle.cs b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/QuerySingle.cs index 073e4ac..20e4fd5 100644 --- a/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/QuerySingle.cs +++ b/Frends.JSON.QuerySingle/Frends.JSON.QuerySingle/QuerySingle.cs @@ -1,4 +1,5 @@ using Frends.JSON.QuerySingle.Definitions; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.ComponentModel; using System.IO; @@ -31,7 +32,12 @@ static JSON() public static Result QuerySingle([PropertyTab] Input input, [PropertyTab] Options options) { JToken jToken = GetJTokenFromInput(input.Json); - return new Result(true, jToken.SelectToken(input.Query, options.ErrorWhenNotMatched)); + JToken result = jToken.SelectToken(input.Query, options.ErrorWhenNotMatched); + + if (result == null && options.ErrorWhenNotMatched) + throw new JsonException($"No matches found for query '{input.Query}'."); + + return new Result(true, result); } private static object GetJTokenFromInput(dynamic json) From a11d2ae3055ad82f106aa340f9c2fb6146f59693 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 07:12:18 +0000 Subject: [PATCH 2/2] Fix ErrorWhenNotMatched not throwing for filter queries with no matches in Query task --- Frends.JSON.Query/CHANGELOG.md | 4 ++++ .../Frends.JSON.Query.UnitTests/UnitTests.cs | 18 ++++++++++++++++++ .../Frends.JSON.Query/Frends.JSON.Query.csproj | 2 +- Frends.JSON.Query/Frends.JSON.Query/Query.cs | 9 ++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Frends.JSON.Query/CHANGELOG.md b/Frends.JSON.Query/CHANGELOG.md index 9c7c721..6a821f1 100644 --- a/Frends.JSON.Query/CHANGELOG.md +++ b/Frends.JSON.Query/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.2.0] - 2026-07-08 +### Fixed +- Fixed issue where Options.ErrorWhenNotMatched did not throw an exception when a JSONPath filter expression (e.g. `[?(...)]`) matched no results. + ## [1.1.0] - 2024-08-20 ### Updated - Updated Newtonsoft.Json library to the latest version 13.0.3. diff --git a/Frends.JSON.Query/Frends.JSON.Query.UnitTests/UnitTests.cs b/Frends.JSON.Query/Frends.JSON.Query.UnitTests/UnitTests.cs index 40899ba..113ad1a 100644 --- a/Frends.JSON.Query/Frends.JSON.Query.UnitTests/UnitTests.cs +++ b/Frends.JSON.Query/Frends.JSON.Query.UnitTests/UnitTests.cs @@ -1,5 +1,6 @@ using Frends.JSON.Query.Definitions; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Frends.JSON.Query.UnitTests; @@ -79,6 +80,23 @@ public void QueryShouldWorkWithJTokenInput() Assert.AreEqual("Anvil", result.Data.First().ToString()); } + [TestMethod] + public void QueryShouldThrowIfOptionSetAndFilterMatchesNothing() + { + var input = new Input() + { + Json = jsonString, + Query = "$..Products[?(@.Price >= 1000)].Name" + }; + + var options = new Options() + { + ErrorWhenNotMatched = true, + }; + + Assert.ThrowsException(() => JSON.Query(input, options)); + } + [TestMethod] public void QueryShouldNotThrowIfOptionNotSetAndNothingIsFound() { diff --git a/Frends.JSON.Query/Frends.JSON.Query/Frends.JSON.Query.csproj b/Frends.JSON.Query/Frends.JSON.Query/Frends.JSON.Query.csproj index a77e388..2be73b3 100644 --- a/Frends.JSON.Query/Frends.JSON.Query/Frends.JSON.Query.csproj +++ b/Frends.JSON.Query/Frends.JSON.Query/Frends.JSON.Query.csproj @@ -2,7 +2,7 @@ net6.0 - 1.1.0 + 1.2.0 Frends Frends Frends diff --git a/Frends.JSON.Query/Frends.JSON.Query/Query.cs b/Frends.JSON.Query/Frends.JSON.Query/Query.cs index b9b7f6d..044ab4a 100644 --- a/Frends.JSON.Query/Frends.JSON.Query/Query.cs +++ b/Frends.JSON.Query/Frends.JSON.Query/Query.cs @@ -1,7 +1,9 @@ using Frends.JSON.Query.Definitions; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.ComponentModel; using System.IO; +using System.Linq; using System.Reflection; using System.Runtime.Loader; @@ -31,7 +33,12 @@ static JSON() public static Result Query([PropertyTab] Input input, [PropertyTab] Options options) { JToken jToken = GetJTokenFromInput(input.Json); - return new Result(true, jToken.SelectTokens(input.Query, options.ErrorWhenNotMatched)); + var tokens = jToken.SelectTokens(input.Query, options.ErrorWhenNotMatched).ToList(); + + if (tokens.Count == 0 && options.ErrorWhenNotMatched) + throw new JsonException($"No matches found for query '{input.Query}'."); + + return new Result(true, tokens); } private static object GetJTokenFromInput(dynamic json)