Print errors through LOG_ERROR

This commit is contained in:
Ivan Lezhankin 2021-01-15 19:57:44 +03:00
parent 1b37d7716f
commit 066242c64d
3 changed files with 19 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#include <Common/Exception.h>
#include <common/logger_useful.h>
#include <Parsers/New/LexerErrorListener.h>
@ -17,7 +18,7 @@ extern int SYNTAX_ERROR;
void LexerErrorListener::syntaxError(Recognizer *, Token *, size_t, size_t, const std::string & message, std::exception_ptr)
{
std::cerr << "Lexer error: " << message << std::endl;
LOG_ERROR(&Poco::Logger::get("ClickHouseLexer"), "Lexer error: {}", message);
throw DB::Exception("Can't recognize input: " + message, ErrorCodes::SYNTAX_ERROR);
}

View File

@ -1,4 +1,5 @@
#include <Common/Exception.h>
#include <common/logger_useful.h>
#include <Parsers/New/ParserErrorListener.h>
@ -24,9 +25,10 @@ void ParserErrorListener::syntaxError(
{
auto * parser = dynamic_cast<ClickHouseParser*>(recognizer);
std::cerr << "Last element parsed so far:" << std::endl
<< parser->getRuleContext()->toStringTree(parser, true) << std::endl
<< "Parser error: (pos " << token->getStartIndex() << ") " << message << std::endl;
LOG_ERROR(&Poco::Logger::get("ClickHouseParser"),
"Last element parsed so far:\n"
"{}\n"
"Parser error: (pos {}) {}", parser->getRuleContext()->toStringTree(parser, true), token->getStartIndex(), message);
throw DB::Exception("Can't parse input: " + message, ErrorCodes::SYNTAX_ERROR);
}

12
src/Parsers/New/README.md Normal file
View File

@ -0,0 +1,12 @@
## How to generate source code files from grammar
Grammar is located inside `ClickHouseLexer.g4` and `ClickHouseParser.g4` files.
To generate source code you need to install locally the `antlr4` binary:
```
cd src/Parsers/New
antlr4 -no-listener -visitor -package DB -Dlanguage=Cpp ClickHouseLexer.g4 # if you have changes in a lexer part of grammar
antlr4 -no-listener -visitor -package DB -Dlanguage=Cpp ClickHouseParser.g4
```
Commit only git-tracked generated files - not all of the generated content is required.