Skip to content

Commit b0d3413

Browse files
authored
Merge branch 'main' into iam-role-log-ingestor
2 parents 10853f6 + f40c9fe commit b0d3413

18 files changed

+282
-293
lines changed

components/core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ set(SOURCE_FILES_unitTest
500500
src/clp/ffi/ir_stream/decoding_methods.inc
501501
src/clp/ffi/ir_stream/encoding_methods.cpp
502502
src/clp/ffi/ir_stream/encoding_methods.hpp
503-
src/clp/ffi/ir_stream/IrErrorCode.cpp
504-
src/clp/ffi/ir_stream/IrErrorCode.hpp
503+
src/clp/ffi/ir_stream/IrDeserializationError.cpp
504+
src/clp/ffi/ir_stream/IrDeserializationError.hpp
505505
src/clp/ffi/ir_stream/IrSerializationError.cpp
506506
src/clp/ffi/ir_stream/IrSerializationError.hpp
507507
src/clp/ffi/ir_stream/IrUnitHandlerReq.hpp

components/core/src/clp/clg/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ set(
2121
../ffi/ir_stream/decoding_methods.cpp
2222
../ffi/ir_stream/decoding_methods.hpp
2323
../ffi/ir_stream/decoding_methods.inc
24+
../ffi/ir_stream/IrDeserializationError.cpp
25+
../ffi/ir_stream/IrDeserializationError.hpp
2426
../ffi/ir_stream/IrSerializationError.cpp
2527
../ffi/ir_stream/IrSerializationError.hpp
2628
../ffi/StringBlob.hpp

components/core/src/clp/clo/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ set(
2727
../ffi/ir_stream/decoding_methods.inc
2828
../ffi/ir_stream/encoding_methods.cpp
2929
../ffi/ir_stream/encoding_methods.hpp
30+
../ffi/ir_stream/IrDeserializationError.cpp
31+
../ffi/ir_stream/IrDeserializationError.hpp
3032
../ffi/ir_stream/IrSerializationError.cpp
3133
../ffi/ir_stream/IrSerializationError.hpp
3234
../ffi/ir_stream/utils.cpp

components/core/src/clp/clp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ set(
2828
../ffi/ir_stream/decoding_methods.inc
2929
../ffi/ir_stream/encoding_methods.cpp
3030
../ffi/ir_stream/encoding_methods.hpp
31-
../ffi/ir_stream/IrErrorCode.cpp
32-
../ffi/ir_stream/IrErrorCode.hpp
31+
../ffi/ir_stream/IrDeserializationError.cpp
32+
../ffi/ir_stream/IrDeserializationError.hpp
3333
../ffi/ir_stream/IrSerializationError.cpp
3434
../ffi/ir_stream/IrSerializationError.hpp
3535
../ffi/ir_stream/utils.cpp

components/core/src/clp/ffi/ir_stream/Deserializer.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class Deserializer {
101101
*
102102
* NOTE: If the deserialized IR unit is `IrUnitType::LogEvent` and the query handler is not
103103
* `search::EmptyQueryHandler`, `handle_log_event` will only be invoked if the query handler
104-
105104
* returns `search::AstEvaluationResult::True`.
106105
*
107106
* @param reader
@@ -375,7 +374,7 @@ auto Deserializer<IrUnitHandler, QueryHandlerType>::deserialize_next_ir_unit(
375374

376375
case IrUnitType::UtcOffsetChange: {
377376
auto const new_utc_offset{
378-
YSTDLIB_ERROR_HANDLING_TRYX(deserialize_ir_unit_utc_offset_change(reader))
377+
YSTDLIB_ERROR_HANDLING_TRYX(deserialize_utc_offset_change(reader))
379378
};
380379
if (auto const err{
381380
m_ir_unit_handler.handle_utc_offset_change(m_utc_offset, new_utc_offset)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "IrDeserializationError.hpp"
2+
3+
#include <string>
4+
5+
#include <ystdlib/error_handling/ErrorCode.hpp>
6+
7+
using clp::ffi::ir_stream::IrDeserializationErrorEnum;
8+
using IrErrorCategory = ystdlib::error_handling::ErrorCategory<IrDeserializationErrorEnum>;
9+
10+
template <>
11+
auto IrErrorCategory::name() const noexcept -> char const* {
12+
return "clp::ffi::ir_stream::IrDeserializationError";
13+
}
14+
15+
template <>
16+
auto IrErrorCategory::message(IrDeserializationErrorEnum error_enum) const -> std::string {
17+
switch (error_enum) {
18+
case IrDeserializationErrorEnum::DuplicateKey:
19+
return "duplicated keys are found in the same kv-pair log event";
20+
case IrDeserializationErrorEnum::EncodedTextAstDeserializationFailure:
21+
return "failed to deserialize an encoded text AST";
22+
case IrDeserializationErrorEnum::EndOfStream:
23+
return "reached end-of-stream IR unit";
24+
case IrDeserializationErrorEnum::IncompleteStream:
25+
return "incomplete IR stream";
26+
case IrDeserializationErrorEnum::InvalidKeyGroupOrdering:
27+
return "invalid key-ID-group ordering";
28+
case IrDeserializationErrorEnum::InvalidTag:
29+
return "invalid tag";
30+
case IrDeserializationErrorEnum::UnsupportedMetadataFormat:
31+
return "IR stream metadata format unsupported";
32+
case IrDeserializationErrorEnum::UnsupportedVersion:
33+
return "IR stream version unsupported";
34+
case IrDeserializationErrorEnum::UnknownSchemaTreeNodeType:
35+
return "unknown schema tree node type";
36+
case IrDeserializationErrorEnum::UnknownValueType:
37+
return "unknown value type";
38+
default:
39+
return "unknown error code enum";
40+
}
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef CLP_IR_DESERIALIZATION_ERROR_HPP
2+
#define CLP_IR_DESERIALIZATION_ERROR_HPP
3+
4+
#include <cstdint>
5+
6+
#include <ystdlib/error_handling/ErrorCode.hpp>
7+
8+
namespace clp::ffi::ir_stream {
9+
/**
10+
* Error code enum for IR stream deserialization.
11+
*/
12+
enum class IrDeserializationErrorEnum : uint8_t {
13+
DuplicateKey,
14+
EncodedTextAstDeserializationFailure,
15+
EndOfStream,
16+
IncompleteStream,
17+
InvalidKeyGroupOrdering,
18+
InvalidTag,
19+
UnsupportedMetadataFormat,
20+
UnsupportedVersion,
21+
UnknownSchemaTreeNodeType,
22+
UnknownValueType,
23+
};
24+
25+
using IrDeserializationError = ystdlib::error_handling::ErrorCode<IrDeserializationErrorEnum>;
26+
} // namespace clp::ffi::ir_stream
27+
28+
YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp::ffi::ir_stream::IrDeserializationErrorEnum);
29+
30+
#endif // CLP_IR_DESERIALIZATION_ERROR_HPP

components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

components/core/src/clp/ffi/ir_stream/decoding_methods.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../EncodedTextAst.hpp"
1313
#include "../StringBlob.hpp"
1414
#include "byteswap.hpp"
15+
#include "IrDeserializationError.hpp"
1516
#include "protocol_constants.hpp"
1617
#include "utils.hpp"
1718

@@ -526,15 +527,15 @@ auto deserialize_encoded_text_ast(
526527

527528
template <ir::EncodedVariableTypeReq encoded_variable_t>
528529
[[nodiscard]] auto deserialize_encoded_text_ast(ReaderInterface& reader, encoded_tag_t encoded_tag)
529-
-> boost::outcome_v2::std_checked<EncodedTextAst<encoded_variable_t>, IRErrorCode> {
530+
-> ystdlib::error_handling::Result<EncodedTextAst<encoded_variable_t>> {
530531
StringBlob string_blob;
531532
vector<encoded_variable_t> encoded_vars;
532533
bool is_encoded_var{};
533534
while (is_variable_tag<encoded_variable_t>(encoded_tag, is_encoded_var)) {
534535
if (is_encoded_var) {
535536
encoded_variable_t encoded_variable{};
536537
if (false == deserialize_int(reader, encoded_variable)) {
537-
return IRErrorCode_Incomplete_IR;
538+
return IrDeserializationError{IrDeserializationErrorEnum::IncompleteStream};
538539
}
539540
encoded_vars.push_back(encoded_variable);
540541
} else {
@@ -543,28 +544,28 @@ template <ir::EncodedVariableTypeReq encoded_variable_t>
543544
};
544545
IRErrorCode_Success != error_code)
545546
{
546-
return error_code;
547+
return IrDeserializationError{
548+
IrDeserializationErrorEnum::EncodedTextAstDeserializationFailure
549+
};
547550
}
548551
}
549552
if (ErrorCode_Success != reader.try_read_numeric_value(encoded_tag)) {
550-
return IRErrorCode_Incomplete_IR;
553+
return IrDeserializationError{IrDeserializationErrorEnum::IncompleteStream};
551554
}
552555
}
553556

554557
if (auto const error_code{deserialize_and_append_logtype(reader, encoded_tag, string_blob)};
555558
IRErrorCode_Success != error_code)
556559
{
557-
return error_code;
560+
return IrDeserializationError{
561+
IrDeserializationErrorEnum::EncodedTextAstDeserializationFailure
562+
};
558563
}
559564

560-
auto encoded_text_ast_result = EncodedTextAst<encoded_variable_t>::create(
565+
return EncodedTextAst<encoded_variable_t>::create(
561566
std::move(encoded_vars),
562567
std::move(string_blob)
563568
);
564-
if (encoded_text_ast_result.has_error()) {
565-
return IRErrorCode_Corrupted_IR;
566-
}
567-
return std::move(encoded_text_ast_result.value());
568569
}
569570

570571
IRErrorCode get_encoding_type(ReaderInterface& reader, bool& is_four_bytes_encoding) {
@@ -596,6 +597,14 @@ IRErrorCode deserialize_tag(ReaderInterface& reader, encoded_tag_t& tag) {
596597
return IRErrorCode_Success;
597598
}
598599

600+
auto deserialize_tag(ReaderInterface& reader) -> ystdlib::error_handling::Result<encoded_tag_t> {
601+
encoded_tag_t tag{};
602+
if (ErrorCode_Success != reader.try_read_numeric_value(tag)) {
603+
return IrDeserializationError{IrDeserializationErrorEnum::IncompleteStream};
604+
}
605+
return tag;
606+
}
607+
599608
IRErrorCode deserialize_preamble(
600609
ReaderInterface& reader,
601610
encoded_tag_t& metadata_type,
@@ -682,6 +691,15 @@ IRErrorCode deserialize_utc_offset_change(ReaderInterface& reader, UtcOffset& ut
682691
return IRErrorCode_Success;
683692
}
684693

694+
auto deserialize_utc_offset_change(ReaderInterface& reader)
695+
-> ystdlib::error_handling::Result<UtcOffset> {
696+
int64_t serialized_utc_offset{};
697+
if (false == deserialize_int(reader, serialized_utc_offset)) {
698+
return IrDeserializationError{IrDeserializationErrorEnum::IncompleteStream};
699+
}
700+
return UtcOffset{serialized_utc_offset};
701+
}
702+
685703
namespace four_byte_encoding {
686704
IRErrorCode deserialize_log_event(
687705
ReaderInterface& reader,
@@ -752,10 +770,10 @@ template auto deserialize_encoded_text_ast<eight_byte_encoded_variable_t>(
752770
template auto deserialize_encoded_text_ast<four_byte_encoded_variable_t>(
753771
ReaderInterface& reader,
754772
encoded_tag_t encoded_tag
755-
) -> boost::outcome_v2::std_checked<EncodedTextAst<four_byte_encoded_variable_t>, IRErrorCode>;
773+
) -> ystdlib::error_handling::Result<EncodedTextAst<four_byte_encoded_variable_t>>;
756774

757775
template auto deserialize_encoded_text_ast<eight_byte_encoded_variable_t>(
758776
ReaderInterface& reader,
759777
encoded_tag_t encoded_tag
760-
) -> boost::outcome_v2::std_checked<EncodedTextAst<eight_byte_encoded_variable_t>, IRErrorCode>;
778+
) -> ystdlib::error_handling::Result<EncodedTextAst<eight_byte_encoded_variable_t>>;
761779
} // namespace clp::ffi::ir_stream

0 commit comments

Comments
 (0)