Report a throwing or open-generic command constructor as a failed load [patch] - #116
Merged
Merged
Conversation
…d [patch] JsonUndoRedoSerializer only translated MissingMethodException from Activator.CreateInstance, so a saved command whose constructor throws (TargetInvocationException) or whose type is an open generic (ArgumentException) escaped LoadStateAsync instead of returning false. Catch every non-cancellation exception there, as the DeserializeData block below already does, and add both cases to the load-failure tests. Fixes #102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM
|
matt-edmondson
deleted the
claude/undoredo-102-constructor-exceptions
branch
September 28, 2026 08:21
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 #102
What was wrong
JsonUndoRedoSerializer.ConvertFromSerializableCommandonly translatedMissingMethodExceptionfromActivator.CreateInstanceinto theInvalidOperationExceptionthatLoadStateAsyncturns intofalse. Two other constructor failures escaped to the caller instead of the documented failed-load result:TargetInvocationExceptionArgumentExceptionChange
Activator.CreateInstance, keep the specificMissingMethodExceptionmessage and add a catch for every other non-cancellation exception. The catch wraps the exception inInvalidOperationException, the same pattern theDeserializeDatablock just below already uses. This also coversTypeInitializationExceptionandMemberAccessException.ThrowingConstructorandOpenGenericcases to the LoadStateAsync throws FileLoadException/InvalidCastException/FormatException on a bad command "type" or data instead of returning false #93 data-driven tests, for both the serializer (JsonSerializer_DeserializeUnloadableCommand_ThrowsInvalidOperationException) and the service (UndoRedoService_LoadStateUnloadableCommand_ReturnsFalseAndKeepsHistory, which returnsfalseand keeps the live stack).Testing
main, all 4 new cases fail with the exceptions the issue reports.dotnet test UndoRedo.Testpasses 104/104.🤖 Generated with Claude Code
https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM
Generated by Claude Code