Skip to content

core: report plugin command exceptions instead of crashing the game - #5940

Open
Alistair-Afton wants to merge 2 commits into
DFHack:developfrom
Alistair-Afton:plugin-invoke-exception-guard
Open

Alistair-Afton wants to merge 2 commits into
DFHack:developfrom
Alistair-Afton:plugin-invoke-exception-guard

Conversation

@Alistair-Afton

Copy link
Copy Markdown
Contributor

Summary

  • Plugin::invoke now wraps command dispatch in an exception boundary: a plugin command that throws (e.g. std::stoi on malformed input, vector::at on an unresolvable index) reports the error and returns CR_FAILURE instead of letting the exception escape Core::runCommand and terminate the game
  • The kittens devel plugin gains a throwtest command that throws std::runtime_error (or a non-std value with throwtest nonstd) to exercise both catch paths
  • Regression test asserts the guarded behavior

Two real crashes motivated this: strangemood --id <non-numeric> (fixed separately in #5939) and 3dveins on tiles whose biome can't be resolved (also fixed in #5939). Both propagated exceptions through runCommand into terminate, killing the game session. This boundary prevents the whole class of failure regardless of which plugin regresses next.

Test plan

  • throwtest and throwtest nonstd both report the exception and leave the game running
  • New kittens tests pass in-game
  • Normal plugin commands unaffected (full test suite green)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant