Adding an optional message to be attached to an InvalidStateError. Testing: Only a refactor, no behavior change Fixes: Partially #39053 Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>