fixed rewrite_error_query