@@ -541,7 +541,7 @@ NodeType get_archive_node_type(
541541 archive_node_type = NodeType::UnstructuredArray;
542542 break ;
543543 case clp::ffi::SchemaTreeNode::Type::Str:
544- if (node_value->is <std::string>()) {
544+ if (node_value && node_value ->is <std::string>()) {
545545 archive_node_type = NodeType::VarString;
546546 } else {
547547 archive_node_type = NodeType::ClpString;
@@ -592,6 +592,8 @@ int JsonParser::get_archive_node_id(
592592 std::string node_key = " " ;
593593 if (validated_escaped_key.has_value ()) {
594594 node_key = validated_escaped_key.value ();
595+ } else {
596+ throw " Key is not utf8 compliant" ;
595597 }
596598 int curr_node_archive_id
597599 = m_archive_writer->add_node (parent_node_id, archive_node_type, node_key);
@@ -616,12 +618,17 @@ void JsonParser::parse_kv_log_event(
616618 } else {
617619 archive_node_type = get_archive_node_type (ir_node_type, node_has_value, {});
618620 }
619- int node_id = get_archive_node_id (
620- ir_node_to_archive_node_map,
621- pair.first ,
622- archive_node_type,
623- tree
624- );
621+ int node_id;
622+ try {
623+ node_id = get_archive_node_id (
624+ ir_node_to_archive_node_map,
625+ pair.first ,
626+ archive_node_type,
627+ tree
628+ );
629+ } catch (...) {
630+ throw ;
631+ }
625632
626633 switch (archive_node_type) {
627634 case NodeType::Integer: {
@@ -637,30 +644,38 @@ void JsonParser::parse_kv_log_event(
637644 m_current_parsed_message.add_value (node_id, b_value);
638645 } break ;
639646 case NodeType::VarString: {
640- std::string str = clp::ffi::validate_and_escape_utf8_string (
641- pair.second .value ().get_immutable_view <std::string>()
642- )
643- .value ();
647+ auto validated_escaped_string = clp::ffi::validate_and_escape_utf8_string (
648+ pair.second .value ().get_immutable_view <std::string>()
649+ );
650+ std::string str = " " ;
651+ if (validated_escaped_string.has_value ()) {
652+ str = validated_escaped_string.value ();
653+ } else {
654+ throw " String is not utf8 compliant" ;
655+ }
644656 m_current_parsed_message.add_value (node_id, str);
645657 } break ;
646658 case NodeType::ClpString: {
647- std::string encoded_str;
659+ std::string encoded_str = " " ;
660+ std::string decodedValue = " " ;
648661 if (pair.second .value ().is <clp::ir::EightByteEncodedTextAst>()) {
649- std::string decodedValue
650- = pair.second .value ()
651- .get_immutable_view <clp::ir::EightByteEncodedTextAst>()
652- .decode_and_unparse ()
653- .value ();
654- encoded_str = clp::ffi::validate_and_escape_utf8_string (decodedValue.c_str ())
655- .value ();
662+ decodedValue = pair.second .value ()
663+ .get_immutable_view <clp::ir::EightByteEncodedTextAst>()
664+ .decode_and_unparse ()
665+ .value ();
666+
656667 } else {
657- std::string decodedValue
658- = pair.second .value ()
659- .get_immutable_view <clp::ir::FourByteEncodedTextAst>()
660- .decode_and_unparse ()
661- .value ();
662- encoded_str = clp::ffi::validate_and_escape_utf8_string (decodedValue.c_str ())
663- .value ();
668+ decodedValue = pair.second .value ()
669+ .get_immutable_view <clp::ir::FourByteEncodedTextAst>()
670+ .decode_and_unparse ()
671+ .value ();
672+ }
673+ auto validated_escaped_encoded_string
674+ = clp::ffi::validate_and_escape_utf8_string (decodedValue.c_str ());
675+ if (validated_escaped_encoded_string.has_value ()) {
676+ encoded_str = validated_escaped_encoded_string.value ();
677+ } else {
678+ throw " Encoded string is not utf8 compliant" ;
664679 }
665680 m_current_parsed_message.add_value (node_id, encoded_str);
666681 } break ;
@@ -695,7 +710,6 @@ void JsonParser::parse_kv_log_event(
695710
696711bool JsonParser::parse_from_IR () {
697712 std::map<std::tuple<int32_t , NodeType>, int32_t > ir_node_to_archive_node_map;
698- // m_archive_writer->add_node(-1, NodeType::Unknown, "root");
699713
700714 for (auto & file_path : m_file_paths) {
701715 int fsize = std::filesystem::file_size (file_path);
@@ -727,13 +741,20 @@ bool JsonParser::parse_from_IR() {
727741
728742 m_current_schema.clear ();
729743 auto const & kv_log_event = kv_log_event_result.value ();
730-
731- parse_kv_log_event (kv_log_event, ir_node_to_archive_node_map);
732-
744+ try {
745+ parse_kv_log_event (kv_log_event, ir_node_to_archive_node_map);
746+ } catch (std::string msg) {
747+ SPDLOG_ERROR (" ERROR: {}" + msg);
748+ zd.close ();
749+ return false ;
750+ } catch (...) {
751+ SPDLOG_ERROR (" ERROR: Encountered error while parsing a kv log event" );
752+ zd.close ();
753+ return false ;
754+ }
733755 m_num_messages++;
734756 if (m_archive_writer->get_data_size () >= m_target_encoded_size) {
735757 ir_node_to_archive_node_map.clear ();
736- // m_archive_writer->add_node(-1, NodeType::Unknown, "root");
737758 split_archive ();
738759 }
739760
0 commit comments