Skip to content

Introduce Centralized Typed Error Model Across SDKs#436

Open
Shalini828 wants to merge 1 commit intoRunanywhereAI:mainfrom
Shalini828:feature/centralized-error-model
Open

Introduce Centralized Typed Error Model Across SDKs#436
Shalini828 wants to merge 1 commit intoRunanywhereAI:mainfrom
Shalini828:feature/centralized-error-model

Conversation

@Shalini828
Copy link

@Shalini828 Shalini828 commented Mar 1, 2026

Summary

Introduced a structured typed error model (rac_error_model_t) to standardize error handling across SDK layers.

Changes

  • Added rac_error_model.h and rac_error_model.cpp
  • Implemented centralized error category mapping
  • Wrapped existing rac_result_t codes into structured model
  • Integrated typed error model into logger for enriched error reporting
  • Updated CMake configuration

Result

  • Centralized, typed, and extensible error handling
  • Consistent error categories across SDK modules
  • Improved debugging and telemetry support

Closes #423


Important

Introduces a centralized structured error model for consistent error handling and reporting across SDKs, enhancing debugging and telemetry support.

  • Behavior:
    • Introduces rac_error_model_t in rac_error_model.h and rac_error_model.cpp for structured error handling.
    • Maps existing rac_result_t codes to error categories in rac_error_model.cpp.
    • Enhances log_to_stderr() in rac_logger.cpp to use rac_error_model_t for detailed error logging.
  • Build Configuration:
    • Updates CMakeLists.txt to include rac_error_model.cpp in the build process.
  • Result:
    • Centralized and consistent error handling across SDKs.
    • Improved error reporting and telemetry support.

This description was created by Ellipsis for 7261465. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Introduced structured error reporting with categorized error information for improved diagnostics.
    • Enhanced error logging to display detailed error codes, categories, and messages instead of raw error codes.

Greptile Summary

This PR introduces a centralized typed error model (rac_error_model_t) that enhances error handling across SDKs by wrapping existing rac_result_t codes with structured metadata (category and human-readable messages).

Key Changes:

  • Added rac_error_model.h defining the structured error model with code, message, and category fields
  • Implemented rac_error_category() to map error codes to semantic categories based on ranges
  • Enhanced logger to output error category and message alongside error codes for better debugging
  • Updated build configuration to include new error model source file

Issues Found:

  • Missing category mapping for cancellation error range (-380 to -389), causing RAC_ERROR_CANCELLED to return "Unknown"
  • Minor code quality issues: unused header include and missing EOF newline

The implementation correctly integrates with existing error infrastructure and provides a clean API for structured error reporting.

Confidence Score: 4/5

  • Safe to merge after fixing the missing cancellation range mapping
  • The PR provides a solid foundation for structured error handling with clean API design and proper integration. One logical error (missing cancellation range) needs correction to ensure all error codes map correctly to categories. The implementation is well-structured and follows existing patterns.
  • Pay close attention to sdk/runanywhere-commons/src/core/rac_error_model.cpp to ensure the cancellation range is added

Important Files Changed

Filename Overview
sdk/runanywhere-commons/include/rac/core/rac_error_model.h Introduces rac_error_model_t struct and API for structured error handling; clean interface design, missing newline at EOF
sdk/runanywhere-commons/src/core/rac_error_model.cpp Implements error category mapping; missing cancellation range (-380 to -389), includes unused <string.h> header
sdk/runanywhere-commons/src/core/rac_logger.cpp Enhanced stderr logging to include error category and message; clean integration with new error model
sdk/runanywhere-commons/CMakeLists.txt Added rac_error_model.cpp to build sources; correct placement in RAC_CORE_SOURCES

Last reviewed commit: 7261465

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 7261465 in 11 seconds. Click for details.
  • Reviewed 130 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_D0Zbnbe3v1dYtNDQ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

A centralized error model system is introduced for the RunAnywhere SDK with a structured type containing error code, message, and category. Functions for constructing error models and mapping error codes to categories are added. The logger is updated to use this model for enhanced error reporting.

Changes

Cohort / File(s) Summary
Build Configuration
sdk/runanywhere-commons/CMakeLists.txt
Adds src/core/rac_error_model.cpp to the core sources set.
Error Model Interface
sdk/runanywhere-commons/include/rac/core/rac_error_model.h
Introduces new public type rac_error_model_t with code, message, and category fields. Defines public functions rac_make_error_model() and rac_error_category() for error construction and categorization.
Error Model Implementation
sdk/runanywhere-commons/src/core/rac_error_model.cpp
Implements error category mapping logic that classifies codes into ranges (Success, Client, Network, Server, Timeout, Validation, Authorization, Unknown) and constructs fully-populated error model objects.
Logger Integration
sdk/runanywhere-commons/src/core/rac_logger.cpp
Updates stderr logging to use the new error model, replacing raw error code output with structured error details (code, category, message).

Sequence Diagram

sequenceDiagram
    participant Logger as Logger
    participant ErrorModel as Error Model System
    participant CategoryMap as Category Mapping
    
    Logger->>ErrorModel: rac_make_error_model(error_code)
    ErrorModel->>CategoryMap: rac_error_category(error_code)
    CategoryMap-->>ErrorModel: category string
    ErrorModel->>ErrorModel: Fetch message via rac_error_message()
    ErrorModel-->>Logger: rac_error_model_t {code, message, category}
    Logger->>Logger: Log structured error details
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through errors with grace,
Categories mapped to their place,
Messages clear, codes unfold,
A structured tale of bugs well-told!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Introduce Centralized Typed Error Model Across SDKs' clearly and accurately summarizes the main change: introducing a structured typed error model for standardized error handling.
Linked Issues check ✅ Passed The PR successfully implements the core objective from issue #423 by introducing a typed error model (rac_error_model_t) with centralized error category mapping and integrating it into the logger for consistent error handling.
Out of Scope Changes check ✅ Passed All changes are directly in-scope: new error model header/implementation, error category mapping, logger integration, and CMake updates align with the stated objective of introducing a centralized typed error model.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description is comprehensive and covers all major sections of the template including summary, type of change classification, and detailed implementation details.

✏️ 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

@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.

🧹 Nitpick comments (3)
sdk/runanywhere-commons/include/rac/core/rac_error_model.h (1)

16-20: Document pointer ownership/lifecycle for message and category.

As per coding guidelines, public C API headers must document lifecycle requirements. The message and category pointers are returned by rac_error_message() and rac_error_category() respectively, which return static string literals. Callers need to know they should not free these pointers and that they remain valid indefinitely.

📝 Suggested documentation enhancement
 typedef struct {
     rac_result_t code;      /**< Numeric error code */
-    const char* message;    /**< Human-readable error message */
-    const char* category;   /**< Error category (e.g., Model, Network, Validation) */
+    const char* message;    /**< Human-readable error message (static string, do not free) */
+    const char* category;   /**< Error category (static string, do not free) */
 } rac_error_model_t;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/runanywhere-commons/include/rac/core/rac_error_model.h` around lines 16 -
20, Update the public header docs for rac_error_model_t to state
ownership/lifetime for the pointers: clarify that the fields message and
category (and the values returned by rac_error_message() and
rac_error_category()) point to static string literals, must not be freed by
callers, and remain valid for the lifetime of the process (i.e., indefinitely);
add this brief note alongside the typedef comment for message and category so
users know they do not own or need to free those pointers.
sdk/runanywhere-commons/src/core/rac_error_model.cpp (2)

6-8: Misleading comment: rac_error_category is part of the public API.

The comment labels this as an "Internal Helper," but rac_error_category is declared in the public header and is part of the public API.

📝 Proposed fix
-// ------------------------------------------------------------
-// Internal Helper: Determine Category from Error Code Range
-// ------------------------------------------------------------
+// ------------------------------------------------------------
+// Public API: Determine Category from Error Code Range
+// ------------------------------------------------------------
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/runanywhere-commons/src/core/rac_error_model.cpp` around lines 6 - 8, The
comment preceding rac_error_category incorrectly calls it an "Internal Helper"
even though rac_error_category is part of the public API; update the comment
near the rac_error_category function to reflect that it is public API (e.g.,
"Public API: Determine Category from Error Code Range" or similar) so the header
and implementation comments are consistent with its public declaration, and
ensure no wording implies it is internal/private.

4-4: Remove unused include.

<string.h> is included but no string functions are used in this file.

🧹 Proposed fix
 `#include` "rac/core/rac_error_model.h"
 `#include` "rac/core/rac_error.h"
-
-#include <string.h>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/runanywhere-commons/src/core/rac_error_model.cpp` at line 4, Remove the
unused C header include by deleting the line that includes <string.h> from
rac_error_model.cpp; ensure no string.h-dependent code remains (there are none),
so simply remove the `#include` <string.h> directive to clean up the translation
unit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@sdk/runanywhere-commons/include/rac/core/rac_error_model.h`:
- Around line 16-20: Update the public header docs for rac_error_model_t to
state ownership/lifetime for the pointers: clarify that the fields message and
category (and the values returned by rac_error_message() and
rac_error_category()) point to static string literals, must not be freed by
callers, and remain valid for the lifetime of the process (i.e., indefinitely);
add this brief note alongside the typedef comment for message and category so
users know they do not own or need to free those pointers.

In `@sdk/runanywhere-commons/src/core/rac_error_model.cpp`:
- Around line 6-8: The comment preceding rac_error_category incorrectly calls it
an "Internal Helper" even though rac_error_category is part of the public API;
update the comment near the rac_error_category function to reflect that it is
public API (e.g., "Public API: Determine Category from Error Code Range" or
similar) so the header and implementation comments are consistent with its
public declaration, and ensure no wording implies it is internal/private.
- Line 4: Remove the unused C header include by deleting the line that includes
<string.h> from rac_error_model.cpp; ensure no string.h-dependent code remains
(there are none), so simply remove the `#include` <string.h> directive to clean up
the translation unit.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 195a1a2 and 7261465.

📒 Files selected for processing (4)
  • sdk/runanywhere-commons/CMakeLists.txt
  • sdk/runanywhere-commons/include/rac/core/rac_error_model.h
  • sdk/runanywhere-commons/src/core/rac_error_model.cpp
  • sdk/runanywhere-commons/src/core/rac_logger.cpp

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +9 to +28
const char* rac_error_category(rac_result_t code) {
if (code >= -109 && code <= -100) return "Initialization";
if (code >= -129 && code <= -110) return "Model";
if (code >= -149 && code <= -130) return "Generation";
if (code >= -179 && code <= -150) return "Network";
if (code >= -219 && code <= -180) return "Storage";
if (code >= -229 && code <= -220) return "Hardware";
if (code >= -249 && code <= -230) return "ComponentState";
if (code >= -279 && code <= -250) return "Validation";
if (code >= -299 && code <= -280) return "Audio";
if (code >= -319 && code <= -300) return "LanguageVoice";
if (code >= -329 && code <= -320) return "Authentication";
if (code >= -349 && code <= -330) return "Security";
if (code >= -369 && code <= -350) return "Extraction";
if (code >= -379 && code <= -370) return "Calibration";
if (code >= -499 && code <= -400) return "ModuleService";
if (code >= -599 && code <= -500) return "PlatformAdapter";
if (code >= -699 && code <= -600) return "Backend";
if (code >= -799 && code <= -700) return "Event";
if (code >= -899 && code <= -800) return "Other";
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing category mapping for cancellation error range (-380 to -389)

The cancellation range is defined in rac_error.h but not handled here, causing RAC_ERROR_CANCELLED (-380) to return "Unknown" instead of "Cancellation".

Suggested change
const char* rac_error_category(rac_result_t code) {
if (code >= -109 && code <= -100) return "Initialization";
if (code >= -129 && code <= -110) return "Model";
if (code >= -149 && code <= -130) return "Generation";
if (code >= -179 && code <= -150) return "Network";
if (code >= -219 && code <= -180) return "Storage";
if (code >= -229 && code <= -220) return "Hardware";
if (code >= -249 && code <= -230) return "ComponentState";
if (code >= -279 && code <= -250) return "Validation";
if (code >= -299 && code <= -280) return "Audio";
if (code >= -319 && code <= -300) return "LanguageVoice";
if (code >= -329 && code <= -320) return "Authentication";
if (code >= -349 && code <= -330) return "Security";
if (code >= -369 && code <= -350) return "Extraction";
if (code >= -379 && code <= -370) return "Calibration";
if (code >= -499 && code <= -400) return "ModuleService";
if (code >= -599 && code <= -500) return "PlatformAdapter";
if (code >= -699 && code <= -600) return "Backend";
if (code >= -799 && code <= -700) return "Event";
if (code >= -899 && code <= -800) return "Other";
const char* rac_error_category(rac_result_t code) {
if (code >= -109 && code <= -100) return "Initialization";
if (code >= -129 && code <= -110) return "Model";
if (code >= -149 && code <= -130) return "Generation";
if (code >= -179 && code <= -150) return "Network";
if (code >= -219 && code <= -180) return "Storage";
if (code >= -229 && code <= -220) return "Hardware";
if (code >= -249 && code <= -230) return "ComponentState";
if (code >= -279 && code <= -250) return "Validation";
if (code >= -299 && code <= -280) return "Audio";
if (code >= -319 && code <= -300) return "LanguageVoice";
if (code >= -329 && code <= -320) return "Authentication";
if (code >= -349 && code <= -330) return "Security";
if (code >= -369 && code <= -350) return "Extraction";
if (code >= -379 && code <= -370) return "Calibration";
if (code >= -389 && code <= -380) return "Cancellation";
if (code >= -499 && code <= -400) return "ModuleService";
if (code >= -599 && code <= -500) return "PlatformAdapter";
if (code >= -699 && code <= -600) return "Backend";
if (code >= -799 && code <= -700) return "Event";
if (code >= -899 && code <= -800) return "Other";
Prompt To Fix With AI
This is a comment left during a code review.
Path: sdk/runanywhere-commons/src/core/rac_error_model.cpp
Line: 9-28

Comment:
Missing category mapping for cancellation error range (-380 to -389)

The cancellation range is defined in `rac_error.h` but not handled here, causing `RAC_ERROR_CANCELLED` (-380) to return "Unknown" instead of "Cancellation".

```suggestion
const char* rac_error_category(rac_result_t code) {
    if (code >= -109 && code <= -100) return "Initialization";
    if (code >= -129 && code <= -110) return "Model";
    if (code >= -149 && code <= -130) return "Generation";
    if (code >= -179 && code <= -150) return "Network";
    if (code >= -219 && code <= -180) return "Storage";
    if (code >= -229 && code <= -220) return "Hardware";
    if (code >= -249 && code <= -230) return "ComponentState";
    if (code >= -279 && code <= -250) return "Validation";
    if (code >= -299 && code <= -280) return "Audio";
    if (code >= -319 && code <= -300) return "LanguageVoice";
    if (code >= -329 && code <= -320) return "Authentication";
    if (code >= -349 && code <= -330) return "Security";
    if (code >= -369 && code <= -350) return "Extraction";
    if (code >= -379 && code <= -370) return "Calibration";
    if (code >= -389 && code <= -380) return "Cancellation";
    if (code >= -499 && code <= -400) return "ModuleService";
    if (code >= -599 && code <= -500) return "PlatformAdapter";
    if (code >= -699 && code <= -600) return "Backend";
    if (code >= -799 && code <= -700) return "Event";
    if (code >= -899 && code <= -800) return "Other";
```

How can I resolve this? If you propose a fix, please make it concise.

#include "rac/core/rac_error_model.h"
#include "rac/core/rac_error.h"

#include <string.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused include - <string.h> is not used anywhere in this file

Suggested change
#include <string.h>
Prompt To Fix With AI
This is a comment left during a code review.
Path: sdk/runanywhere-commons/src/core/rac_error_model.cpp
Line: 4

Comment:
Unused include - `<string.h>` is not used anywhere in this file

```suggestion
```

How can I resolve this? If you propose a fix, please make it concise.

}
#endif

#endif // RAC_ERROR_MODEL_H No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline at end of file

Suggested change
#endif // RAC_ERROR_MODEL_H
#endif // RAC_ERROR_MODEL_H
Prompt To Fix With AI
This is a comment left during a code review.
Path: sdk/runanywhere-commons/include/rac/core/rac_error_model.h
Line: 36

Comment:
Missing newline at end of file

```suggestion
#endif // RAC_ERROR_MODEL_H
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Collaborator

@Siddhesh2377 Siddhesh2377 left a comment

Choose a reason for hiding this comment

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

The PR works but has a confirmed bug: add the missing range to rac_error_model.cpp:
if (code >= -389 && code <= -380) return "Cancellation";

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.

Introduce Centralized Error Handling & Typed Error Model Across All SDKs

2 participants