aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-dataloader/csv/Parser.cpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2024-05-11 20:37:50 +0200
committer Spartan322 <Megacake1234@gmail.com>2024-05-11 22:27:30 +0200
commit458180da5e61887cd9f820e573f307d0a640128d (patch)
treec0b7aa641b72b5f2650691cba22d17de335622f6 /src/openvic-dataloader/csv/Parser.cpp
parent725310939d2b324d79ea4193a72000e21dcc1a2a (diff)
Fix bugs in #37fix/error-handling
Fix error handling dropping errors Fix error handling segfaults Improve error messages
Diffstat (limited to 'src/openvic-dataloader/csv/Parser.cpp')
-rw-r--r--src/openvic-dataloader/csv/Parser.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/openvic-dataloader/csv/Parser.cpp b/src/openvic-dataloader/csv/Parser.cpp
index 849ea05..361f6ad 100644
--- a/src/openvic-dataloader/csv/Parser.cpp
+++ b/src/openvic-dataloader/csv/Parser.cpp
@@ -142,8 +142,8 @@ constexpr Parser<Encoding>& Parser<Encoding>::load_from_string(const std::string
}
template<EncodingType Encoding>
-constexpr Parser<Encoding>& Parser<Encoding>::load_from_file(const char* path) {
- _file_path = path;
+Parser<Encoding>& Parser<Encoding>::load_from_file(const char* path) {
+ set_file_path(path);
// Type can be deduced??
_run_load_func(std::mem_fn(&ParseHandler::load_file), path);
return *this;
@@ -224,15 +224,21 @@ void Parser<Encoding>::print_errors_to(std::basic_ostream<char>& stream) const {
dryad::visit_tree(
error,
[&](const error::BufferError* buffer_error) {
- stream << buffer_error->message() << '\n';
+ stream << "buffer error: " << buffer_error->message() << '\n';
},
[&](const error::ParseError* parse_error) {
- stream << parse_error->message() << '\n';
+ auto position = get_error_position(parse_error);
+ std::string pos_str = fmt::format(":{}:{}: ", position.start_line, position.start_column);
+ stream << _file_path << pos_str << "parse error for '" << parse_error->production_name() << "': " << parse_error->message() << '\n';
},
[&](dryad::child_visitor<error::ErrorKind> visitor, const error::Semantic* semantic) {
- stream << semantic->message() << '\n';
+ auto position = get_error_position(semantic);
+ std::string pos_str = ": ";
+ if (!position.is_empty()) {
+ pos_str = fmt::format(":{}:{}: ", position.start_line, position.start_column);
+ }
+ stream << _file_path << pos_str << semantic->message() << '\n';
auto annotations = semantic->annotations();
- if (annotations.empty()) return;
for (auto annotation : annotations) {
visitor(annotation);
}