diff --git a/cql3/error_collector.hh b/cql3/error_collector.hh index c7ce4fc834..9a49714c78 100644 --- a/cql3/error_collector.hh +++ b/cql3/error_collector.hh @@ -67,10 +67,6 @@ class error_collector : public error_listener */ const sstring_view _query; - /** - * The error messages. - */ - std::vector _error_msgs; public: /** @@ -81,7 +77,10 @@ public: */ error_collector(const sstring_view& query) : _query(query) {} - virtual void syntax_error(RecognizerType& recognizer, ANTLR_UINT8** token_names, ExceptionBaseType* ex) override { + /** + * Format and throw a new \c exceptions::syntax_exception. + */ + [[noreturn]] virtual void syntax_error(RecognizerType& recognizer, ANTLR_UINT8** token_names, ExceptionBaseType* ex) override { auto hdr = get_error_header(ex); auto msg = get_error_message(recognizer, ex, token_names); std::stringstream result; @@ -90,22 +89,15 @@ public: if (recognizer instanceof Parser) appendQuerySnippet((Parser) recognizer, builder); #endif - _error_msgs.emplace_back(result.str()); - } - virtual void syntax_error(RecognizerType& recognizer, const sstring& msg) override { - _error_msgs.emplace_back(msg); + throw exceptions::syntax_exception(result.str()); } /** - * Throws the first syntax error found by the lexer or the parser if it exists. - * - * @throws SyntaxException the syntax error. + * Throw a new \c exceptions::syntax_exception. */ - void throw_first_syntax_error() { - if (!_error_msgs.empty()) { - throw exceptions::syntax_exception(_error_msgs[0]); - } + [[noreturn]] virtual void syntax_error(RecognizerType&, const sstring& msg) override { + throw exceptions::syntax_exception(msg); } private: diff --git a/cql3/util.hh b/cql3/util.hh index a8bbacb7fe..77ec553015 100644 --- a/cql3/util.hh +++ b/cql3/util.hh @@ -51,8 +51,6 @@ Result do_with_parser(const sstring_view& cql, Func&& f) { cql3_parser::CqlParser parser{&tstream}; parser.set_error_listener(parser_error_collector); auto result = f(parser); - lexer_error_collector.throw_first_syntax_error(); - parser_error_collector.throw_first_syntax_error(); return result; }