better error checking, fixes #7660
better error clearing, fixes #7754