Skip to content

Comments

refactor(kv-ir): Improve error handling in clp::ffi::ir_stream::Serializer.#2000

Open
jonathan-imanu wants to merge 7 commits intoy-scope:mainfrom
jonathan-imanu:ir_stream_error_handling
Open

refactor(kv-ir): Improve error handling in clp::ffi::ir_stream::Serializer.#2000
jonathan-imanu wants to merge 7 commits intoy-scope:mainfrom
jonathan-imanu:ir_stream_error_handling

Conversation

@jonathan-imanu
Copy link
Contributor

@jonathan-imanu jonathan-imanu commented Feb 16, 2026

Description

This PR refactors the clp::ffi::ir_stream::Serializer API to replace the bool and std::errc return types with typed Result<T, IrErrorCode>. This provides more descriptive error reporting for IR stream serialization failures. It updates tests accordingly. It is the first step in addressing #904

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Unit + integration tests

Summary by CodeRabbit

  • Bug Fixes

    • Standardized and clarified IR stream error messages (formatting/wording).
  • New Features

    • Added explicit serialization error codes for IR stream failures (schema, metadata, key/value, ID, unsupported types).
  • Refactor

    • Replaced many boolean success/failure returns with typed error-result semantics to improve error propagation and diagnostics.
  • Tests

    • Updated tests to check result engagement and inspect error codes instead of boolean truthiness.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Added a new IrSerializationError enum/type and error-category implementation, refactored IR serialization APIs and helpers to return typed ystdlib::error_handling::Result<void, IrSerializationError> (and adjusted related call sites/tests), and adjusted IrErrorCode message text casing and punctuation.

Changes

Cohort / File(s) Summary
IrErrorCode text tweaks
components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp, components/core/src/clp/ffi/ir_stream/IrErrorCode.hpp
Lowercased several IrErrorCodeEnum message strings, removed trailing periods, and updated the default unknown message; narrowed Doxygen comment to deserialization context.
New serialization error type
components/core/src/clp/ffi/ir_stream/IrSerializationError.hpp, components/core/src/clp/ffi/ir_stream/IrSerializationError.cpp
Added IrSerializationErrorEnum, IrSerializationError alias, macro registration, and an ErrorCategory implementation mapping enum values to human-readable messages.
Serializer API & impl changes
components/core/src/clp/ffi/ir_stream/Serializer.hpp, components/core/src/clp/ffi/ir_stream/Serializer.cpp
Refactored serialization-related concepts and functions to use a SerializationResult = Result<void, IrErrorCode/IrSerializationError>-style return (error-first); updated create() to return Result<Serializer<...>, IrSerializationError> and replaced boolean-based control flow with error propagation (TRYV / explicit error returns).
Utilities updated
components/core/src/clp/ffi/ir_stream/utils.hpp
encode_and_serialize_schema_tree_node_id now returns Result<void, IrSerializationError>; out-of-range IDs return SchemaTreeNodeIdSerializationFailure; added IrSerializationError include.
Test helpers & integration
components/core/src/clp/ffi/ir_stream/search/test/utils.hpp, components/core/src/clp/ffi/ir_stream/search/test/test_deserializer_integration.cpp
unpack_and_serialize_msgpack_bytes signature changed to Result<void, IrSerializationError>; tests updated to assert .has_value() or .has_error() instead of boolean results; added includes.
Tests updated
components/core/tests/test-clp_s-range_index.cpp, components/core/tests/test-ir_encoding_methods.cpp
Assertions migrated to use .has_value()/.has_error() and inspect IrSerializationErrorEnum where relevant; added IrErrorCode.hpp include.
Log converter
components/core/src/clp_s/log_converter/LogSerializer.cpp, components/core/src/clp_s/log_converter/LogSerializer.hpp
Replaced manual error checks with YSTDLIB_ERROR_HANDLING_TRYV to propagate serializer errors; documentation updated to reflect serializer return semantics.
Build file updates
components/core/src/clp_s/CMakeLists.txt, components/core/CMakeLists.txt, components/core/src/clp/clp/CMakeLists.txt
Added IrErrorCode.* and IrSerializationError.* to source lists so new headers/sources are built into targets and tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring error handling in the Serializer to use typed Result types instead of bool/std::errc returns.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
components/core/src/clp/ffi/ir_stream/Serializer.cpp (1)

592-713: ⚠️ Potential issue | 🟠 Major

Preserve schema‑tree node errors during map serialization.
Failures from serialize_schema_tree_node are collapsed into KeyValuePairSerializationFailure, so SchemaTreeNodeSerializationFailure is never surfaced. Capture and return the underlying error when DFS fails; this also avoids the negated has_error() checks.

💡 Proposed fix to preserve schema‑tree node errors
+    std::optional<IrErrorCode> schema_tree_error;
     auto auto_gen_schema_tree_node_serialization_method
-            = [this](SchemaTree::NodeLocator const& locator) -> bool {
-        return !this->serialize_schema_tree_node<true>(locator).has_error();
-    };
+            = [this, &schema_tree_error](SchemaTree::NodeLocator const& locator) -> bool {
+        auto const result = this->serialize_schema_tree_node<true>(locator);
+        if (result.has_error()) {
+            schema_tree_error = result.error();
+            return false;
+        }
+        return true;
+    };

@@
-    if (0 != auto_gen_kv_pairs_map.size
-        && false
-                   == serialize_msgpack_map_using_dfs(
-                           auto_gen_kv_pairs_map,
-                           m_auto_gen_keys_schema_tree,
-                           auto_gen_schema_tree_node_serialization_method,
-                           auto_gen_node_id_value_pairs_serialization_method,
-                           auto_gen_empty_map_serialization_method
-                   ))
-    {
-        return IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure};
-    }
+    if (0 != auto_gen_kv_pairs_map.size
+        && false
+                   == serialize_msgpack_map_using_dfs(
+                           auto_gen_kv_pairs_map,
+                           m_auto_gen_keys_schema_tree,
+                           auto_gen_schema_tree_node_serialization_method,
+                           auto_gen_node_id_value_pairs_serialization_method,
+                           auto_gen_empty_map_serialization_method
+                   ))
+    {
+        if (schema_tree_error.has_value()) {
+            return schema_tree_error.value();
+        }
+        return IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure};
+    }
+
+    schema_tree_error.reset();

     auto user_gen_schema_tree_node_serialization_method
-            = [this](SchemaTree::NodeLocator const& locator) -> bool {
-        return !this->serialize_schema_tree_node<false>(locator).has_error();
-    };
+            = [this, &schema_tree_error](SchemaTree::NodeLocator const& locator) -> bool {
+        auto const result = this->serialize_schema_tree_node<false>(locator);
+        if (result.has_error()) {
+            schema_tree_error = result.error();
+            return false;
+        }
+        return true;
+    };

@@
-        if (false
-            == serialize_msgpack_map_using_dfs(
-                    user_gen_kv_pairs_map,
-                    m_user_gen_keys_schema_tree,
-                    user_gen_schema_tree_node_serialization_method,
-                    user_gen_node_id_value_pairs_serialization_method,
-                    user_gen_empty_map_serialization_method
-            ))
-        {
-            return IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure};
-        }
+        if (false
+            == serialize_msgpack_map_using_dfs(
+                    user_gen_kv_pairs_map,
+                    m_user_gen_keys_schema_tree,
+                    user_gen_schema_tree_node_serialization_method,
+                    user_gen_node_id_value_pairs_serialization_method,
+                    user_gen_empty_map_serialization_method
+            ))
+        {
+            if (schema_tree_error.has_value()) {
+                return schema_tree_error.value();
+            }
+            return IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure};
+        }
As per coding guidelines, prefer `false == ` rather than `!`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/core/src/clp/ffi/ir_stream/Serializer.cpp` around lines 592 - 713,
The map-DFS currently collapses errors from serialize_schema_tree_node into a
generic KeyValuePairSerializationFailure; change
auto_gen_schema_tree_node_serialization_method and
user_gen_schema_tree_node_serialization_method to return and propagate the
actual IrErrorCode (or Result) from serialize_schema_tree_node instead of
returning bool via !has_error(), then update serialize_msgpack_map_using_dfs
call sites to capture and return that underlying error when it fails (return the
SchemaTreeNodeSerializationFailure when appropriate) rather than always
returning IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure}; also
replace occurrences of !expr with the preferred style (false == expr) as per
guidelines.
components/core/src/clp_s/log_converter/LogSerializer.hpp (1)

58-69: ⚠️ Potential issue | 🟡 Minor

Update the no‑timestamp overload docs to match the new error code.
The overload below still references std::errc::invalid_argument, but failures now propagate IrErrorCodeEnum::KeyValuePairSerializationFailure.

✏️ Suggested doc fix
-     * - std::errc::invalid_argument if `clp::ffi::ir_stream::Serializer<>::serialize_msgpack_map`
-     *   returns on failure.
+     * - IrErrorCodeEnum::KeyValuePairSerializationFailure if
+     *   `clp::ffi::ir_stream::Serializer<>::serialize_msgpack_map` fails.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/core/src/clp_s/log_converter/LogSerializer.hpp` around lines 58 -
69, Update the doc comment for the no-timestamp overload of add_message (the
overload declared as add_message(std::string_view message)) to state that
failures now return IrErrorCodeEnum::KeyValuePairSerializationFailure instead of
std::errc::invalid_argument; edit the bullet under `@return` to replace the old
enum with IrErrorCodeEnum::KeyValuePairSerializationFailure and keep the
description that it originates from
clp::ffi::ir_stream::Serializer<>::serialize_msgpack_map failures.
🤖 Fix all issues with AI agents
Verify each finding against the current code and only fix it if needed.


In `@components/core/src/clp_s/log_converter/LogSerializer.hpp`:
- Around line 58-69: Update the doc comment for the no-timestamp overload of
add_message (the overload declared as add_message(std::string_view message)) to
state that failures now return IrErrorCodeEnum::KeyValuePairSerializationFailure
instead of std::errc::invalid_argument; edit the bullet under `@return` to replace
the old enum with IrErrorCodeEnum::KeyValuePairSerializationFailure and keep the
description that it originates from
clp::ffi::ir_stream::Serializer<>::serialize_msgpack_map failures.

In `@components/core/src/clp/ffi/ir_stream/Serializer.cpp`:
- Around line 592-713: The map-DFS currently collapses errors from
serialize_schema_tree_node into a generic KeyValuePairSerializationFailure;
change auto_gen_schema_tree_node_serialization_method and
user_gen_schema_tree_node_serialization_method to return and propagate the
actual IrErrorCode (or Result) from serialize_schema_tree_node instead of
returning bool via !has_error(), then update serialize_msgpack_map_using_dfs
call sites to capture and return that underlying error when it fails (return the
SchemaTreeNodeSerializationFailure when appropriate) rather than always
returning IrErrorCode{IrErrorCodeEnum::KeyValuePairSerializationFailure}; also
replace occurrences of !expr with the preferred style (false == expr) as per
guidelines.

In `@components/core/tests/test-ir_encoding_methods.cpp`:
- Around line 411-419: The conditional checks using negation should be rewritten
to the repository style using explicit equality to false: replace occurrences
like "!serializer.serialize_msgpack_map(...).has_error()" with "false ==
serializer.serialize_msgpack_map(...).has_error()" for the calls to
serializer.serialize_msgpack_map involving msgpack_obj.via.map and
msgpack_empty_map_obj.via.map so both branches use the `false == <expression>`
style when testing has_error().

Comment on lines 411 to 419
if (!serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_error())
{
// Serialization should fail
return false;
}
if (serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)) {
if (!serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)
.has_error())
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the specific lines in the file
cat -n components/core/tests/test-ir_encoding_methods.cpp | sed -n '405,425p'

Repository: y-scope/clp

Length of output: 989


🏁 Script executed:

# Search for coding style guidelines in the repository
fd -t f -e md -e txt -e rst | xargs grep -l "false ==" | head -20

Repository: y-scope/clp

Length of output: 37


🏁 Script executed:

# Check if there's a STYLE, CODING_GUIDELINES, or similar documentation file
fd -t f \( -name "*STYLE*" -o -name "*GUIDE*" -o -name "*CONVENTION*" \) | head -20

Repository: y-scope/clp

Length of output: 285


🏁 Script executed:

# Search for how error checks are typically done in the test file
grep -n "\.has_error()" components/core/tests/test-ir_encoding_methods.cpp | head -20

Repository: y-scope/clp

Length of output: 878


🏁 Script executed:

# Check the broader context around lines 411-419
cat -n components/core/tests/test-ir_encoding_methods.cpp | sed -n '400,430p'

Repository: y-scope/clp

Length of output: 1328


🏁 Script executed:

# Let's check if there's a CODING_GUIDELINES or similar document to confirm this style rule
find . -type f \( -name "*.md" -o -name "*.txt" -o -name ".clang-format" -o -name "CONTRIBUTING*" \) | head -20

Repository: y-scope/clp

Length of output: 911


🏁 Script executed:

# Let's also check the clang-format configuration if it exists
find . -name ".clang-format" -o -name "clang-format" | xargs cat 2>/dev/null | head -50

Repository: y-scope/clp

Length of output: 761


Use false == style instead of ! for error checks.

Align these conditionals with the repository's coding style guideline that prefers false == <expression> rather than !<expression>.

Suggested change
-    if (!serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
-                 .has_error())
+    if (false
+        == serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
+                   .has_error())
     {
         // Serialization should fail
         return false;
     }
-    if (!serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)
-                 .has_error())
+    if (false
+        == serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)
+                   .has_error())
     {
         // Serialization should fail
         return false;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_error())
{
// Serialization should fail
return false;
}
if (serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)) {
if (!serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)
.has_error())
{
if (false
== serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_error())
{
// Serialization should fail
return false;
}
if (false
== serializer.serialize_msgpack_map(msgpack_empty_map_obj.via.map, msgpack_obj.via.map)
.has_error())
{
// Serialization should fail
return false;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/core/tests/test-ir_encoding_methods.cpp` around lines 411 - 419,
The conditional checks using negation should be rewritten to the repository
style using explicit equality to false: replace occurrences like
"!serializer.serialize_msgpack_map(...).has_error()" with "false ==
serializer.serialize_msgpack_map(...).has_error()" for the calls to
serializer.serialize_msgpack_map involving msgpack_obj.via.map and
msgpack_empty_map_obj.via.map so both branches use the `false == <expression>`
style when testing has_error().

@jonathan-imanu jonathan-imanu changed the title refactor(kv-ir): Improve error handling in clp::ffi::ir_stream::Serializer (addresses #904). refactor(kv-ir): Improve error handling in clp::ffi::ir_stream::Serializer. Feb 17, 2026
@jonathan-imanu jonathan-imanu marked this pull request as ready for review February 17, 2026 23:45
@jonathan-imanu jonathan-imanu requested review from a team and gibber9809 as code owners February 17, 2026 23:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp`:
- Around line 25-37: Reorder the switch cases in IrErrorCode.cpp to match the
enum declaration order in IrErrorCode.hpp: MetadataSerializationFailure,
SchemaTreeNodeSerializationFailure, KeyValuePairSerializationFailure,
UnsupportedUserDefinedMetadata, UnsupportedSchemaTreeNodeType,
SchemaTreeNodeIdSerializationFailure; update the case blocks for IrErrorCodeEnum
to that sequence so reviewers can easily verify coverage and maintain parity
with the IrErrorCodeEnum declaration.

In `@components/core/src/clp/ffi/ir_stream/Serializer.cpp`:
- Around line 598-627: Inline the temporary encode_result when calling
YSTDLIB_ERROR_HANDLING_TRYV to remove the redundant variable: replace the
pattern where encode_result =
encode_and_serialize_schema_tree_node_id<...>(node_id,
m_sequential_serialization_buf); YSTDLIB_ERROR_HANDLING_TRYV(encode_result);
with a direct call
YSTDLIB_ERROR_HANDLING_TRYV(encode_and_serialize_schema_tree_node_id<...>(node_id,
m_sequential_serialization_buf)); do this for every lambda that calls
encode_and_serialize_schema_tree_node_id (e.g., the auto-generated value-pair
lambda that precedes serialize_value and
auto_gen_empty_map_serialization_method) so the code calls
YSTDLIB_ERROR_HANDLING_TRYV(...) inline and otherwise leaves serialize_value,
serialize_value_empty_object, and m_sequential_serialization_buf usage
unchanged.

Comment on lines 25 to 37
case IrErrorCodeEnum::KeyValuePairSerializationFailure:
return "Failed to serialize a key-value pair log event.";
case IrErrorCodeEnum::MetadataSerializationFailure:
return "Failed to serialize the stream's metadata.";
case IrErrorCodeEnum::SchemaTreeNodeSerializationFailure:
return "Failed to serialize a schema tree node.";
case IrErrorCodeEnum::SchemaTreeNodeIdSerializationFailure:
return "Failed to serialize a schema tree node ID. The ID exceeds the representable "
"range.";
case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
return "The schema tree node type is not supported.";
case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
return "The user-defined metadata is not a valid JSON object.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Nit: Switch case ordering doesn't match the enum declaration order.

In IrErrorCode.hpp, the enum members are declared in the order: MetadataSerializationFailure, SchemaTreeNodeSerializationFailure, KeyValuePairSerializationFailure, UnsupportedUserDefinedMetadata, UnsupportedSchemaTreeNodeType, SchemaTreeNodeIdSerializationFailure. Here the switch cases use a different order. Matching the declaration order makes it easier to verify that all cases are covered.

🔧 Suggested reordering to match the enum declaration
-        case IrErrorCodeEnum::KeyValuePairSerializationFailure:
-            return "Failed to serialize a key-value pair log event.";
         case IrErrorCodeEnum::MetadataSerializationFailure:
             return "Failed to serialize the stream's metadata.";
         case IrErrorCodeEnum::SchemaTreeNodeSerializationFailure:
             return "Failed to serialize a schema tree node.";
+        case IrErrorCodeEnum::KeyValuePairSerializationFailure:
+            return "Failed to serialize a key-value pair log event.";
+        case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
+            return "The user-defined metadata is not a valid JSON object.";
+        case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
+            return "The schema tree node type is not supported.";
         case IrErrorCodeEnum::SchemaTreeNodeIdSerializationFailure:
             return "Failed to serialize a schema tree node ID. The ID exceeds the representable "
                    "range.";
-        case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
-            return "The schema tree node type is not supported.";
-        case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
-            return "The user-defined metadata is not a valid JSON object.";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case IrErrorCodeEnum::KeyValuePairSerializationFailure:
return "Failed to serialize a key-value pair log event.";
case IrErrorCodeEnum::MetadataSerializationFailure:
return "Failed to serialize the stream's metadata.";
case IrErrorCodeEnum::SchemaTreeNodeSerializationFailure:
return "Failed to serialize a schema tree node.";
case IrErrorCodeEnum::SchemaTreeNodeIdSerializationFailure:
return "Failed to serialize a schema tree node ID. The ID exceeds the representable "
"range.";
case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
return "The schema tree node type is not supported.";
case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
return "The user-defined metadata is not a valid JSON object.";
case IrErrorCodeEnum::MetadataSerializationFailure:
return "Failed to serialize the stream's metadata.";
case IrErrorCodeEnum::SchemaTreeNodeSerializationFailure:
return "Failed to serialize a schema tree node.";
case IrErrorCodeEnum::KeyValuePairSerializationFailure:
return "Failed to serialize a key-value pair log event.";
case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
return "The user-defined metadata is not a valid JSON object.";
case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
return "The schema tree node type is not supported.";
case IrErrorCodeEnum::SchemaTreeNodeIdSerializationFailure:
return "Failed to serialize a schema tree node ID. The ID exceeds the representable "
"range.";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/core/src/clp/ffi/ir_stream/IrErrorCode.cpp` around lines 25 - 37,
Reorder the switch cases in IrErrorCode.cpp to match the enum declaration order
in IrErrorCode.hpp: MetadataSerializationFailure,
SchemaTreeNodeSerializationFailure, KeyValuePairSerializationFailure,
UnsupportedUserDefinedMetadata, UnsupportedSchemaTreeNodeType,
SchemaTreeNodeIdSerializationFailure; update the case blocks for IrErrorCodeEnum
to that sequence so reviewers can easily verify coverage and maintain parity
with the IrErrorCodeEnum declaration.

Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some high-level comments to fix.
I will review the docstring changes in detail in the next round.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since IrErrorCode is std::errc compatible, I think returning a ystlib::error_handling::Result<T> should be better. This allows us to call methods that also return a std::errc on error (which can come from another library that doesn't use IrErrorCode).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at this, I think it might be worth distinguishing the serialization and deserialization errors.
How about:

  • For this PR, let's introduce IrSerializationErrorEnum and IrSerializationError, and leave IrErrorCodeEnum and IrErrorCode untouched.
  • In the deserialization PR, let's rename IrErrorCodeEnum and IrErrorCode to IrDeserializationErrorEnum and IrDeserializationError.

Comment on lines 25 to 37
case IrErrorCodeEnum::KeyValuePairSerializationFailure:
return "Failed to serialize a key-value pair log event.";
case IrErrorCodeEnum::MetadataSerializationFailure:
return "Failed to serialize the stream's metadata.";
case IrErrorCodeEnum::SchemaTreeNodeSerializationFailure:
return "Failed to serialize a schema tree node.";
case IrErrorCodeEnum::SchemaTreeNodeIdSerializationFailure:
return "Failed to serialize a schema tree node ID. The ID exceeds the representable "
"range.";
case IrErrorCodeEnum::UnsupportedSchemaTreeNodeType:
return "The schema tree node type is not supported.";
case IrErrorCodeEnum::UnsupportedUserDefinedMetadata:
return "The user-defined metadata is not a valid JSON object.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing error messages are a bit outdated. We should follow the latest rule which:

  • Don't capitalize the first character
  • Don't add a period at the end

This is because normally, this error message is added to a format string and printed in the log. The above changes would make this formatted string easier to manage.


namespace clp::ffi::ir_stream {
namespace {
using SerializationResult = ystdlib::error_handling::Result<void, IrErrorCode>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I think we don't need this alias. Using the default error type std::errc should be sufficient.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@components/core/src/clp/ffi/ir_stream/Serializer.cpp`:
- Around line 614-620: Multiple places create a redundant local variable
encode_result immediately passed to the YSTDLIB_ERROR_HANDLING_TRYV macro;
remove the intermediate variable and invoke the macro directly with the call to
encode_and_serialize_schema_tree_node_id<...>(...) instead. Update all
occurrences (the four lambdas inside serialize_msgpack_map and the
serialize_schema_tree_node function) to replace patterns like auto encode_result
= encode_and_serialize_schema_tree_node_id<...>(...);
YSTDLIB_ERROR_HANDLING_TRYV(encode_result); with a single
YSTDLIB_ERROR_HANDLING_TRYV(encode_and_serialize_schema_tree_node_id<...>(...));
keeping the same template parameters, node_id argument, and
m_sequential_serialization_buf usage so behavior is unchanged.

In `@components/core/tests/test-ir_encoding_methods.cpp`:
- Around line 412-425: The test uses "true == ... .has_value()" which is
inconsistent with the repo's established pattern; change both checks that call
serializer.serialize_msgpack_map(...) to instead assert the negative has_error
pattern (use "false == <result>.has_error()") so the positive success assertion
matches other tests — locate the calls to serialize_msgpack_map with
msgpack_obj.via.map and msgpack_empty_map_obj.via.map and replace the
has_value() style with false == <result>.has_error() for consistency.

Comment on lines +105 to +107
* - Forwards `Serializer::serialize_msgpack_map`'s return values.
* - IrSerializationErrorEnum::KeyValuePairSerializationFailure if the msgpack bytes don't
* represent maps.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - Forwards `Serializer::serialize_msgpack_map`'s return values.
* - IrSerializationErrorEnum::KeyValuePairSerializationFailure if the msgpack bytes don't
* represent maps.
* - IrSerializationErrorEnum::KeyValuePairSerializationFailure if the msgpack bytes cannot be
* deserialized into a map.
* - Forwards `Serializer::serialize_msgpack_map`'s return values.

A little rewording.
Also, we prefer to list returned enums before forwarded errors.

Comment on lines 113 to +118
REQUIRE(unpack_and_serialize_msgpack_bytes(
nlohmann::json::to_msgpack(auto_gen_kv_pairs),
nlohmann::json::to_msgpack(user_gen_kv_pairs),
serializer
));
nlohmann::json::to_msgpack(auto_gen_kv_pairs),
nlohmann::json::to_msgpack(user_gen_kv_pairs),
serializer
)
.has_value());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        REQUIRE_FALSE(unpack_and_serialize_msgpack_bytes(
                              nlohmann::json::to_msgpack(auto_gen_kv_pairs),
                              nlohmann::json::to_msgpack(user_gen_kv_pairs),
                              serializer
        )
                              .has_error());

We prefer to use .has_error to check if the result contains an error.

/**
* This enum class represents all possible error codes related to serializing or deserializing CLP
* IR streams.
* This enum class represents error codes for IR stream deserialization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This enum class represents error codes for IR stream deserialization
* Error code enum for IR stream deserialization.


namespace clp::ffi::ir_stream {
/**
* This enum class represents error codes for IR stream serialization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This enum class represents error codes for IR stream serialization
* Error code enum for IR stream serialization.

Comment on lines +27 to +28
return "failed to serialize a schema tree node ID (the ID exceeds the representable "
"range)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "failed to serialize a schema tree node ID (the ID exceeds the representable "
"range)";
return "failed to serialize a schema tree node ID";

Since we didn't include details in other error enums, I think it's fair to keep it simple.

MetadataSerializationFailure,
SchemaTreeNodeSerializationFailure,
SchemaTreeNodeIdSerializationFailure,
UnsupportedSchemaTreeNodeType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about UnsupportedSchemaTreeNodeType -> UnknownSchemaTreeNodeType (and also need to update the error message))?

Comment on lines +119 to +123
* - IrSerializationErrorEnum::UnsupportedSchemaTreeNodeType if the node type is unsupported.
* - IrSerializationErrorEnum::SchemaTreeNodeIdSerializationFailure if the parent node ID
* couldn't be serialized.
* - IrSerializationErrorEnum::SchemaTreeNodeSerializationFailure if the key name couldn't be
* serialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - IrSerializationErrorEnum::UnsupportedSchemaTreeNodeType if the node type is unsupported.
* - IrSerializationErrorEnum::SchemaTreeNodeIdSerializationFailure if the parent node ID
* couldn't be serialized.
* - IrSerializationErrorEnum::SchemaTreeNodeSerializationFailure if the key name couldn't be
* serialized.
* - IrSerializationErrorEnum::UnsupportedSchemaTreeNodeType if the node type is unsupported.
* - IrSerializationErrorEnum::SchemaTreeNodeSerializationFailure if the key name couldn't be
* serialized.
* - Forwards `encode_and_serialize_schema_tree_node_id`'s return value on failure.

Comment on lines +88 to +90
REQUIRE(
serializer.serialize_msgpack_map(auto_gen_obj.via.map, user_gen_obj.via.map).has_value()
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
REQUIRE(
serializer.serialize_msgpack_map(auto_gen_obj.via.map, user_gen_obj.via.map).has_value()
);
REQUIRE_FALSE(
serializer.serialize_msgpack_map(auto_gen_obj.via.map, user_gen_obj.via.map).has_error()
);

Comment on lines +412 to +414
if (true
== serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_value())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (true
== serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_value())
if (false
== serializer.serialize_msgpack_map(msgpack_obj.via.map, msgpack_empty_map_obj.via.map)
.has_error())

Btw we don't need true == condition; we only use false == xxx for Yoda condition.

Comment on lines +1517 to +1520
REQUIRE(
(clp::ffi::ir_stream::IrSerializationErrorEnum::UnsupportedUserDefinedMetadata
== serializer_result.error().get_error())
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
REQUIRE(
(clp::ffi::ir_stream::IrSerializationErrorEnum::UnsupportedUserDefinedMetadata
== serializer_result.error().get_error())
);
using clp::ffi::ir_stream::IrSerializationError;
using clp::ffi::ir_stream::IrSerializationErrorEnum;
REQUIRE(IrSerializationError{IrSerializationErrorEnum::UnsupportedUserDefinedMetadata}
== serializer_result.error());

The error enum itself is not strong-typed. Need to check the error object by constructing an IrSerializationError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants