From de30dc76774e5e2f5c05570a96054207febb3ccf Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 10:03:25 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #72 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Data/issues/72 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..bb371c9 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Data/issues/72 +Your prepared branch: issue-72-67b8d7f8 +Your prepared working directory: /tmp/gh-issue-solver-1757746999417 + +Proceed. \ No newline at end of file From e0ee1ee2feb24c589e6e22e741900fb48a809615 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 10:21:15 +0300 Subject: [PATCH 2/3] Add null check in GetLink method and throw ArgumentLinkDoesNotExistsException MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix issue #72 by adding a null check after calling links.Each() in the GetLink method. When no link is found, the Setter.Result remains null, and the method now throws ArgumentLinkDoesNotExistsException instead of returning null. This prevents downstream methods like IsFullPoint and IsPartialPoint from receiving null values and failing. Also added comprehensive tests to verify the fix works correctly for both existing and non-existing links. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../ILinksExtensionsTests.cs | 76 +++++++++++++++++++ csharp/Platform.Data/ILinksExtensions.cs | 7 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 csharp/Platform.Data.Tests/ILinksExtensionsTests.cs diff --git a/csharp/Platform.Data.Tests/ILinksExtensionsTests.cs b/csharp/Platform.Data.Tests/ILinksExtensionsTests.cs new file mode 100644 index 0000000..51d55a4 --- /dev/null +++ b/csharp/Platform.Data.Tests/ILinksExtensionsTests.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using Xunit; +using Platform.Data.Exceptions; +using Platform.Delegates; + +namespace Platform.Data.Tests +{ + /// + /// Tests for ILinksExtensions methods + /// + public static class ILinksExtensionsTests + { + private class MockLinks : ILinks> + { + private readonly LinksConstants _constants; + + public MockLinks() + { + _constants = new LinksConstants(enableExternalReferencesSupport: true); + } + + public LinksConstants Constants => _constants; + + public ulong Count(IList? restriction) => 0; + + public ulong Each(IList? restriction, ReadHandler? handler) + { + // Return Constants.Break to simulate no matching links found + return _constants.Break; + } + + public ulong Create(IList? substitution, WriteHandler? handler) => 0; + + public ulong Update(IList? restriction, IList? substitution, WriteHandler? handler) => 0; + + public ulong Delete(IList? restriction, WriteHandler? handler) => 0; + } + + /// + /// Tests that GetLink throws ArgumentLinkDoesNotExistsException when link doesn't exist + /// + [Fact] + public static void GetLinkThrowsExceptionWhenLinkDoesNotExist() + { + var links = new MockLinks(); + var nonExistentLinkId = 999UL; + + // The mock implementation returns Constants.Break from Each, which means no link was found + // and the Setter.Result remains null, so GetLink should throw ArgumentLinkDoesNotExistsException + var exception = Assert.Throws>(() => + links.GetLink(nonExistentLinkId)); + + // Verify the exception contains the correct link id (checking if it's in the message) + Assert.Contains(nonExistentLinkId.ToString(), exception.Message); + } + + /// + /// Tests that GetLink works correctly for external references + /// + [Fact] + public static void GetLinkWorksForExternalReferences() + { + var links = new MockLinks(); + var externalReference = new Hybrid(0, true); // External reference + + // For external references, GetLink should return a Point without calling Each + var result = links.GetLink(externalReference); + + Assert.NotNull(result); + // The Point should contain the external reference value + Assert.Equal(externalReference.Value, result[0]); + } + } +} \ No newline at end of file diff --git a/csharp/Platform.Data/ILinksExtensions.cs b/csharp/Platform.Data/ILinksExtensions.cs index 4fcf77a..303d138 100644 --- a/csharp/Platform.Data/ILinksExtensions.cs +++ b/csharp/Platform.Data/ILinksExtensions.cs @@ -148,7 +148,12 @@ public static TLinkAddress Each(this ILinks?, TLinkAddress>(constants.Continue, constants.Break); links.Each(linkPartsSetter.SetAndReturnTrue, link); - return linkPartsSetter.Result; + var result = linkPartsSetter.Result; + if (result == null) + { + throw new ArgumentLinkDoesNotExistsException(link); + } + return result; } #region Points From 6544f4642b9980235738f2c3284eff81b4bd3a9b Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 10:22:00 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index bb371c9..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Data/issues/72 -Your prepared branch: issue-72-67b8d7f8 -Your prepared working directory: /tmp/gh-issue-solver-1757746999417 - -Proceed. \ No newline at end of file