Skip to content

Commit 9aa6401

Browse files
committed
Fix
1 parent 3b6657c commit 9aa6401

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ydb/public/lib/ydb_cli/common/csv_parser.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TCsvParseException : public TMisuseException {
1414
if (ColumnName.has_value()) {
1515
*this << "Csv parsing error on line " << Line << " in column \"" << ColumnName << "\": ";
1616
} else {
17-
*this << "Csv parsing error on line " << Line << "\": ";
17+
*this << "Csv parsing error on line " << Line << ": ";
1818
}
1919
}
2020

@@ -323,11 +323,19 @@ TValue TCsvParser::FieldToValue(TTypeParser& parser, TStringBuf token) const {
323323
return converter.Convert(token);
324324
}
325325

326+
TStringBuf TCsvParser::Consume(NCsvFormat::CsvSplitter& splitter) const {
327+
try {
328+
return splitter.Consume();
329+
} catch (std::exception& e) {
330+
throw TCsvParseException() << e.what();
331+
}
332+
}
333+
326334
void TCsvParser::GetParams(TString&& data, TParamsBuilder& builder) const {
327335
NCsvFormat::CsvSplitter splitter(data, Delimeter);
328336
auto headerIt = Header.begin();
329337
do {
330-
TStringBuf token = splitter.Consume();
338+
TStringBuf token = Consume(splitter);
331339
if (headerIt == Header.end()) {
332340
throw TCsvParseException() << "Header contains less fields than data. Header: \"" << HeaderRow << "\", data: \"" << data << "\"";
333341
}
@@ -362,7 +370,7 @@ void TCsvParser::GetValue(TString&& data, TValueBuilder& builder, const TType& t
362370
auto headerIt = Header.cbegin();
363371
std::map<TString, TStringBuf> fields;
364372
do {
365-
TStringBuf token = splitter.Consume();
373+
TStringBuf token = Consume(splitter);;
366374
if (headerIt == Header.cend()) {
367375
throw TCsvParseException() << "Header contains less fields than data. Header: \"" << HeaderRow << "\", data: \"" << data << "\"";
368376
}

ydb/public/lib/ydb_cli/common/csv_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TCsvParser {
2727
void GetParams(TString&& data, TParamsBuilder& builder) const;
2828
void GetValue(TString&& data, TValueBuilder& builder, const TType& type) const;
2929
TType GetColumnsType() const;
30+
TStringBuf Consume(NCsvFormat::CsvSplitter& splitter) const;
3031

3132
private:
3233
TValue FieldToValue(TTypeParser& parser, TStringBuf token) const;

0 commit comments

Comments
 (0)