Accept error code by error name in client test hints

This commit is contained in:
Azat Khuzhin 2021-08-08 20:08:36 +03:00
parent 098a0b2012
commit c5d9676779
6 changed files with 24 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include <sstream>
#include <iostream>
#include <Common/Exception.h>
#include <Common/ErrorCodes.h>
#include <Parsers/Lexer.h>
namespace DB
@ -23,10 +24,18 @@ int parseErrorCode(std::stringstream & ss) // STYLE_CHECK_ALLOW_STD_STRING_STREA
using namespace DB;
int code;
String code_name;
ss >> code;
if (ss.fail())
throw Exception(ErrorCodes::CANNOT_PARSE_TEXT,
"Expected integer value for test hint, got: '{}'", ss.str());
{
ss.clear();
ss >> code_name;
if (ss.fail())
throw Exception(ErrorCodes::CANNOT_PARSE_TEXT,
"Cannot parse test hint '{}'", ss.str());
return ErrorCodes::getErrorCodeByName(code_name);
}
return code;
}

View File

@ -15,6 +15,10 @@ namespace DB
///
/// - "-- { clientError 20 }" -- in case of you are expecting client error.
///
/// - "-- { serverError FUNCTION_THROW_IF_VALUE_IS_NON_ZERO }" -- by error name.
///
/// - "-- { clientError FUNCTION_THROW_IF_VALUE_IS_NON_ZERO }" -- by error name.
///
/// Remember that the client parse the query first (not the server), so for
/// example if you are expecting syntax error, then you should use
/// clientError not serverError.

View File

@ -0,0 +1 @@
select throwIf(1); -- { serverError FUNCTION_THROW_IF_VALUE_IS_NON_ZERO }

View File

@ -0,0 +1 @@
No error code with name: 'FOOBAR'. (NO_SUCH_ERROR_CODE)

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CLIENT --testmode -n -q 'select 1 -- { clientError FOOBAR }' |& grep -o 'No error code with name:.*'