Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

Fixes issue #72 by adding proper error handling in the GetLink method in ILinksExtensions.cs.

The issue was that when a link doesn't exist (is not an external reference and has no data in the links storage), the Setter.Result would remain null, but the method was returning this null value without checking. Later methods like IsFullPoint and IsPartialPoint would receive this null value and fail when calling Ensure.Always.ArgumentNotEmpty(link, nameof(link)).

Changes made:

  • Fix in GetLink method (ILinksExtensions.cs:141-157): Added null check after links.Each() call. If the result is null (meaning no link was found), the method now throws ArgumentLinkDoesNotExistsException<TLinkAddress> with the link address that was not found.

  • Added comprehensive tests (ILinksExtensionsTests.cs): Created unit tests to verify:

    • The method throws the correct exception when a link doesn't exist
    • The method works correctly for external references (existing behavior preserved)
    • The exception contains the correct link address in the error message

Behavior before fix:

  • GetLink would return null for non-existent links
  • Downstream methods would fail with unclear errors when processing null values

Behavior after fix:

  • GetLink throws ArgumentLinkDoesNotExistsException<TLinkAddress> immediately when link is not found
  • Clear error message indicating which specific link does not exist
  • Consistent with existing error handling patterns in the codebase (similar to EnsureLinkExists method)

Test plan

  • Unit tests pass for both exception case and normal operation
  • Existing tests continue to pass (no regressions)
  • Build succeeds without compilation errors
  • Exception message contains the correct link address for debugging

🤖 Generated with Claude Code


Resolves #72

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #72
@konard konard self-assigned this Sep 13, 2025
…xception

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 <noreply@anthropic.com>
@konard konard changed the title [WIP] Check for unset result in GetLink method and throw an exception if the link is not found Fix GetLink method to throw exception when link does not exist Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 07:22
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.

Check for unset result in GetLink method and throw an exception if the link is not found

2 participants