Fix GetLink method to throw exception when link does not exist #162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes issue #72 by adding proper error handling in the
GetLinkmethod inILinksExtensions.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.Resultwould remain null, but the method was returning this null value without checking. Later methods likeIsFullPointandIsPartialPointwould receive this null value and fail when callingEnsure.Always.ArgumentNotEmpty(link, nameof(link)).Changes made:
Fix in
GetLinkmethod (ILinksExtensions.cs:141-157): Added null check afterlinks.Each()call. If the result is null (meaning no link was found), the method now throwsArgumentLinkDoesNotExistsException<TLinkAddress>with the link address that was not found.Added comprehensive tests (
ILinksExtensionsTests.cs): Created unit tests to verify:Behavior before fix:
GetLinkwould returnnullfor non-existent linksnullvaluesBehavior after fix:
GetLinkthrowsArgumentLinkDoesNotExistsException<TLinkAddress>immediately when link is not foundEnsureLinkExistsmethod)Test plan
🤖 Generated with Claude Code
Resolves #72