Report every unloadable saved command as a failed load - #99
Merged
Merged
Conversation
LoadStateAsync promises to return false for data it cannot load, but a malformed assembly-qualified type name threw FileLoadException, a type that implements ISerializableCommand without ICommand threw InvalidCastException, and a command whose DeserializeData rejected its data let that exception escape. Translate each into InvalidOperationException with the original as the inner exception, the way the missing-constructor case already is, and check for ICommand before constructing the command. Fixes #93 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N4m2HJkrsY88XBtTqTKAkE
…d-command-type # Conflicts: # UndoRedo.Test/SerializationTests.cs
|
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 #93
What changed
LoadStateAsyncpromises to returnfalsefor data it cannot load. Three failures insideJsonUndoRedoSerializer.ConvertFromSerializableCommandthrew raw exceptions instead, which escaped itsJsonException/InvalidOperationException/NotSupportedExceptionfilter:type/data"Foo, =bad"FileLoadExceptionfalse"Foo, Bar, Version=abc"FileLoadExceptionfalseISerializableCommandbut notICommandInvalidCastExceptionfalseDeserializeDatacallsint.Parse("abc")FormatExceptionfalseThe serializer now turns each of these into
InvalidOperationException, with the original exception kept as the inner exception. This is the same treatmentMissingMethodExceptionalready gets:Type.GetTypeis wrapped in a smallResolveCommandTypehelper. It catchesIOException,BadImageFormatException,ArgumentExceptionandTypeLoadException. A type that simply isn't found still returnsnulland falls back to a placeholder, as before.ICommandcheck happens before the command is constructed.DeserializeDatais the command's own code, so any exception from it is wrapped.OperationCanceledExceptionis let through. TheCA1031pragma follows the pattern already used inCompositeCommandandUndoRedoService.Tests
JsonSerializer_DeserializeUnloadableCommand_ThrowsInvalidOperationExceptionhas one case per row of the table.UndoRedoService_LoadStateUnloadableCommand_ReturnsFalseAndKeepsHistoryruns the same four cases throughLoadStateAsyncand checks the live history is kept.All 8 new cases failed on
mainwith the exceptions listed in the issue. The full suite passes with the change (77/77), and the library builds for every target framework.🤖 Generated with Claude Code
https://claude.ai/code/session_01N4m2HJkrsY88XBtTqTKAkE
Generated by Claude Code