Improve error handling

Reviewer: @vishnu-emmadi

There are some known unimplemented error cases marked by "NYI" assertions. These changes fix all of them.