Updated error checking to ensure an error is present before testing code