Make line method work on errors too

This commit is contained in:
ado 2023-08-06 19:56:28 +02:00
parent 6b4f456654
commit 7df96d95c7
2 changed files with 11 additions and 14 deletions

View File

@ -84,9 +84,9 @@ public:
return to_object<T>(get_next<Ts...>());
}
// TODO make the method work with if valid() returns false
size_t line() const {
return valid() ? reader_.line_number_ - 1 : 0;
return reader_.line_number_ > 1 ? reader_.line_number_ - 1
: reader_.line_number_;
}
template <typename T, typename... Ts>
@ -193,7 +193,7 @@ public:
reader_.next_line_converter_.set_column_mapping(column_mappings,
header_.size());
if (line() == 0) {
if (line() == 1) {
ignore_next();
}
}
@ -622,13 +622,11 @@ private:
void decorate_rethrow(const ss::exception& e) const {
static_assert(throw_on_error,
"throw_on_error needs to be enabled to use this method");
auto line = reader_.line_number_;
throw ss::exception{
std::string{file_name_}
.append(" ")
.append(std::to_string(line > 1 ? line - 1 : line))
.append(": ")
.append(e.what())};
throw ss::exception{std::string{file_name_}
.append(" ")
.append(std::to_string(line()))
.append(": ")
.append(e.what())};
}
////////////////

View File

@ -2386,9 +2386,9 @@ public:
return to_object<T>(get_next<Ts...>());
}
// TODO make the method work with if valid() returns false
size_t line() const {
return valid() ? reader_.line_number_ - 1 : 0;
return reader_.line_number_ > 1 ? reader_.line_number_ - 1
: reader_.line_number_;
}
template <typename T, typename... Ts>
@ -2924,11 +2924,10 @@ private:
void decorate_rethrow(const ss::exception& e) const {
static_assert(throw_on_error,
"throw_on_error needs to be enabled to use this method");
auto line = reader_.line_number_;
throw ss::exception{
std::string{file_name_}
.append(" ")
.append(std::to_string(line > 1 ? line - 1 : line))
.append(std::to_string(line()))
.append(": ")
.append(e.what())};
}