Skip to content

Commit 652c970

Browse files
authored
Added output of success statuses with issues in CLI (#9819)
1 parent 1bc55db commit 652c970

File tree

5 files changed

+25
-35
lines changed

5 files changed

+25
-35
lines changed

ydb/public/lib/ydb_cli/commands/query_workload.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,8 @@ int TCommandQueryWorkloadRun::Run(TConfig& config) {
123123
while (!IsInterrupted())
124124
{
125125
auto streamPart = result.ReadNext().GetValueSync();
126-
if (!streamPart.IsSuccess()) {
127-
if (streamPart.EOS()) {
128-
break;
129-
}
130-
131-
ThrowOnError(streamPart);
126+
if (ThrowOnErrorAndCheckEOS(streamPart)) {
127+
break;
132128
}
133129

134130
if (streamPart.GetStats()) {

ydb/public/lib/ydb_cli/commands/ydb_common.h

+12
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,17 @@ inline void ThrowOnError(const NYdb::TOperation& operation) {
3434
ThrowOnError(operation.Status());
3535
}
3636

37+
inline bool ThrowOnErrorAndCheckEOS(NYdb::TStreamPartStatus status) {
38+
if (!status.IsSuccess()) {
39+
if (status.EOS()) {
40+
return true;
41+
}
42+
throw TYdbErrorException(status) << static_cast<TStatus>(status);
43+
} else if (status.GetIssues()) {
44+
Cerr << static_cast<TStatus>(status);
45+
}
46+
return false;
47+
}
48+
3749
}
3850
}

ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,8 @@ bool TCommandExecuteQuery::PrintQueryResponse(TIterator& result) {
746746

747747
while (!IsInterrupted()) {
748748
auto streamPart = result.ReadNext().GetValueSync();
749-
if (!streamPart.IsSuccess()) {
750-
if (streamPart.EOS()) {
751-
break;
752-
}
753-
ThrowOnError(streamPart);
749+
if (ThrowOnErrorAndCheckEOS(streamPart)) {
750+
break;
754751
}
755752

756753
if (streamPart.HasResultSet()) {
@@ -896,11 +893,8 @@ int TCommandExplain::Run(TConfig& config) {
896893
SetInterruptHandlers();
897894
while (!IsInterrupted()) {
898895
auto tablePart = result.ReadNext().GetValueSync();
899-
if (!tablePart.IsSuccess()) {
900-
if (tablePart.EOS()) {
901-
break;
902-
}
903-
ThrowOnError(tablePart);
896+
if (ThrowOnErrorAndCheckEOS(tablePart)) {
897+
break;
904898
}
905899
if (tablePart.HasQueryStats()) {
906900
auto proto = NYdb::TProtoAccessor::GetProto(tablePart.GetQueryStats());
@@ -939,11 +933,8 @@ int TCommandExplain::Run(TConfig& config) {
939933
SetInterruptHandlers();
940934
while (!IsInterrupted()) {
941935
auto tablePart = result.ReadNext().GetValueSync();
942-
if (!tablePart.IsSuccess()) {
943-
if (tablePart.EOS()) {
944-
break;
945-
}
946-
ThrowOnError(tablePart);
936+
if (ThrowOnErrorAndCheckEOS(tablePart)) {
937+
break;
947938
}
948939
if (tablePart.GetStats()) {
949940
auto proto = NYdb::TProtoAccessor::GetProto(*tablePart.GetStats());
@@ -1179,12 +1170,9 @@ void TCommandReadTable::PrintResponse(NTable::TTablePartIterator& result) {
11791170

11801171
while (!IsInterrupted()) {
11811172
auto tablePart = result.ReadNext().GetValueSync();
1182-
if (!tablePart.IsSuccess()) {
1183-
if (tablePart.EOS()) {
1173+
if (ThrowOnErrorAndCheckEOS(tablePart)) {
11841174
break;
11851175
}
1186-
ThrowOnError(tablePart);
1187-
}
11881176
if (CountOnly) {
11891177
TResultSetParser parser(tablePart.ExtractPart());
11901178
while (parser.TryNextRow()) {

ydb/public/lib/ydb_cli/commands/ydb_sql.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,8 @@ int TCommandSql::PrintResponse(NQuery::TExecuteQueryIterator& result) {
125125

126126
while (!IsInterrupted()) {
127127
auto streamPart = result.ReadNext().GetValueSync();
128-
if (!streamPart.IsSuccess()) {
129-
if (streamPart.EOS()) {
130-
break;
131-
}
132-
ThrowOnError(streamPart);
128+
if (ThrowOnErrorAndCheckEOS(streamPart)) {
129+
break;
133130
}
134131

135132
if (streamPart.HasResultSet() && !ExplainAnalyzeMode) {

ydb/public/lib/ydb_cli/commands/ydb_yql.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,8 @@ bool TCommandYql::PrintResponse(NScripting::TYqlResultPartIterator& result) {
145145

146146
while (!IsInterrupted()) {
147147
auto streamPart = result.ReadNext().GetValueSync();
148-
if (!streamPart.IsSuccess()) {
149-
if (streamPart.EOS()) {
150-
break;
151-
}
152-
ThrowOnError(streamPart);
148+
if (ThrowOnErrorAndCheckEOS(streamPart)) {
149+
break;
153150
}
154151

155152
if (streamPart.HasPartialResult()) {

0 commit comments

Comments
 (0)