Improve invalid query error messages