factor out another common error checking pattern