Task error handling

This patchset fixes a couple of problems with task error handling.