mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Accept error code by error name in client test hints
This commit is contained in:
parent
098a0b2012
commit
c5d9676779
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -0,0 +1 @@
|
||||
select throwIf(1); -- { serverError FUNCTION_THROW_IF_VALUE_IS_NON_ZERO }
|
@ -0,0 +1 @@
|
||||
No error code with name: 'FOOBAR'. (NO_SUCH_ERROR_CODE)
|
7
tests/queries/0_stateless/02006_client_test_hint_no_such_error_name.sh
Executable file
7
tests/queries/0_stateless/02006_client_test_hint_no_such_error_name.sh
Executable 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:.*'
|
Loading…
Reference in New Issue
Block a user