fix incorrect handling of error