Repository navigation
Throw from Serialize when TrySerialize fails [minor] - #115
Merged
Merged
Conversation
ISerializationProvider.Serialize(object) and Serialize(object, TextWriter) discarded TrySerialize's false, so a failed serialization returned "". The file-backed persistence providers wrote that empty string over the last good value and StoreAsync reported success. Both now throw InvalidOperationException, as Encode, Hash and Decrypt already do. StoreAsync's existing catch wraps it in PersistenceProviderException before any file is touched, so the stored value survives. This changes the public behaviour of Serialize, hence the minor bump. Fixes #70 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YLmoTmY5N7amW8Z9jazuGV
|
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.



Fixes #70
What was wrong
The default
ISerializationProvider.Serialize(object)andSerialize(object, TextWriter)ignored the result ofTrySerialize. A failed serialization came back as"".FileSystemPersistenceProvider.StoreAsyncandTempPersistenceProvider.StoreAsync(and through them ConfigHome and DataHome) wrote that empty string over the last good value, and still reported success.Change
Serializeoverloads now throwInvalidOperationExceptionwhenTrySerializereturnsfalse. This is howEncode,HashandDecryptalready behave.Serialize(object)goes through theTextWriteroverload, so the check lives in one place, andSerializeAsyncinherits it.catchinStoreAsyncwraps the exception inPersistenceProviderExceptionbefore any file is written, so the previous value is kept.Serializenow throws where it used to return"", which is a public behaviour change, so the commit carries[minor].Tests
Serialize_Throws_When_TrySerialize_Fails: both overloads throw for a cyclic object graph.Store_Of_An_Unserializable_Value_Throws_And_Keeps_The_Previous_Value: on the FileSystem and Temp providers, store a good value, then try to store a cyclic one.StoreAsyncthrowsPersistenceProviderException, andRetrieveAsyncstill returns the good value.Both tests fail on
main("no exception was thrown") and pass with this change. The fullEssentials.Testssuite passes on net10.0 (1037 tests), andEssentials.csprojbuilds for every target framework with no warnings.🤖 Generated with Claude Code
https://claude.ai/code/session_01YLmoTmY5N7amW8Z9jazuGV
Generated by Claude Code