(PE-3194) improve shutdown-on-error error handling

Ensure that `shutdown-on-error` never throws an exception by replacing
its pre-conditions with assertions inside the body of the function,
so that if they fail, the error will be handled properly.
Merge pull request #130 from KevinCorcoran/shutdown-on-error

(PE-3194) improve shutdown-on-error error handling