query error checking