core: report plugin command exceptions instead of crashing the game - #5940
Open
Alistair-Afton wants to merge 2 commits into
Open
Alistair-Afton wants to merge 2 commits into
Alistair-Afton wants to merge 2 commits into
Conversation
A plugin command that throws (e.g. std::stoi on bad input, .at() on an unresolvable index) used to propagate through Core::runCommand and terminate the game. Catch exceptions in Plugin::invoke and report them as command failures instead. The kittens devel plugin gains a throwtest command to exercise both the std::exception and non-std paths.
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
Plugin::invokenow wraps command dispatch in an exception boundary: a plugin command that throws (e.g.std::stoion malformed input,vector::aton an unresolvable index) reports the error and returnsCR_FAILUREinstead of letting the exception escapeCore::runCommandand terminate the gamekittensdevel plugin gains athrowtestcommand that throwsstd::runtime_error(or a non-std value withthrowtest nonstd) to exercise both catch pathsTwo real crashes motivated this:
strangemood --id <non-numeric>(fixed separately in #5939) and3dveinson tiles whose biome can't be resolved (also fixed in #5939). Both propagated exceptions throughrunCommandintoterminate, killing the game session. This boundary prevents the whole class of failure regardless of which plugin regresses next.Test plan
throwtestandthrowtest nonstdboth report the exception and leave the game runningkittenstests pass in-game