Improve error messages when database access is disposed (#174)#474
Open
konard wants to merge 4 commits into
Open
Improve error messages when database access is disposed (#174)#474konard wants to merge 4 commits into
konard wants to merge 4 commits into
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #174
Previously, when a Links instance was disposed and users tried to access it, they would receive generic null reference exceptions or other non-descriptive errors. This made it difficult to understand what went wrong. This commit adds proper ObjectDisposedException handling to all public database access methods with a clear, descriptive error message: - Added EnsureNotDisposed() method to all Links base classes - Throws ObjectDisposedException with meaningful message: "Cannot access a disposed Links instance. The database connection has been closed and is no longer available for operations." - Applied to all public methods: Count(), Create(), Update(), Delete(), Each() - Covers all implementations: UnitedMemoryLinksBase, SplitMemoryLinksBase, FFI Links, and UInt32Links - Added comprehensive tests to verify the fix works correctly Now when users accidentally access disposed Links instances, they get clear error messages that explain the problem and help them understand what needs to be fixed in their code. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR fixes GitHub issue #174 by implementing better error messages when database access is disposed right after the access is created.
Problem
Previously, when a
Linksinstance was disposed and users tried to access database methods (Count(),Create(),Update(),Delete(),Each()), they would encounter:This made debugging difficult for users who accidentally tried to use disposed database connections.
Solution
Added comprehensive disposal checking to all public database access methods across all
Linksimplementations:Key Changes:
Added
EnsureNotDisposed()method to all Links base classes:UnitedMemoryLinksBase<T>SplitMemoryLinksBase<T>Links<T>(FFI)UInt32Links(FFI)Clear, descriptive error message:
Applied to all public methods:
Count(IList<TLinkAddress>? restriction)Create(IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)Update(IList<TLinkAddress>? restriction, IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)Delete(IList<TLinkAddress>? restriction, WriteHandler<TLinkAddress>? handler)Each(IList<TLinkAddress>? restriction, ReadHandler<TLinkAddress>? handler)Testing
DisposalErrorMessagesTests.cs) that verifies:ObjectDisposedExceptionwhen called on disposed instancesExample Usage
Before (unclear error):
After (clear error):
Impact
Test plan
🤖 Generated with Claude Code
Resolves #174