Convert an assert that can fail into error checking.