Handle better state errors

This fixes #9983.
Merge pull request #9988 from makinacorpus/handleerror

Handle better state errors