replace improper assert with raising error