Skip to content

Introduce Centralized Typed Error Model Across SDKs#436

Open
Shalini828 wants to merge 2 commits intoRunanywhereAI:mainfrom
Shalini828:feature/centralized-error-model
Open

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

Conversation

@Shalini828
Copy link
Copy Markdown

@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: errors now surface as a compact model containing code, category and human-readable message to aid diagnosis.
    • Enhanced logging: stderr output shows the error code, its categorized type and descriptive message instead of only a raw numeric code, improving clarity during troubleshooting.

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
Copy Markdown

@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
Copy Markdown

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

Adds a typed error model (code, message, category), implements category mapping and a constructor, wires the model into the logger, and adds the new source to CMake. No API signatures for existing entities were removed.

Changes

Cohort / File(s) Summary
Build Configuration
sdk/runanywhere-commons/CMakeLists.txt
Adds src/core/rac_error_model.cpp to the RAC_CORE_SOURCES list.
Error Model Interface
sdk/runanywhere-commons/include/rac/core/rac_error_model.h
New public type rac_error_model_t (code, message, category) and declarations for rac_make_error_model(rac_result_t) and rac_error_category(rac_result_t).
Error Model Implementation
sdk/runanywhere-commons/src/core/rac_error_model.cpp
Implements rac_error_category (maps code ranges to category strings) and rac_make_error_model (populates model using rac_error_message and category).
Logger Integration
sdk/runanywhere-commons/src/core/rac_logger.cpp
Includes the error model header and replaces raw error_code printing with constructing and logging rac_error_model_t (code, category, message).

Sequence Diagram

sequenceDiagram
    participant Logger as Logger
    participant ErrorModel as Error Model
    participant CategoryMap as Category Mapper

    Logger->>ErrorModel: rac_make_error_model(error_code)
    ErrorModel->>CategoryMap: rac_error_category(error_code)
    CategoryMap-->>ErrorModel: "Category" (string)
    ErrorModel->>ErrorModel: rac_error_message(error_code)
    ErrorModel-->>Logger: rac_error_model_t {code, message, category}
    Logger->>Logger: log code, category, message to stderr
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble codes and sort their art,

category, message, every part.
From logger's burrow I now sing,
Structured errors — what joy they bring! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description includes Summary and Changes sections clearly explaining modifications, but lacks Type of Change, Testing, Platform-Specific Testing, Labels, and Checklist sections required by the template. Complete the template by adding Type of Change (New feature), Testing sections with checkboxes, Labels selection, and final Checklist items for consistency and governance compliance.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Introduce Centralized Typed Error Model Across SDKs' clearly and concisely summarizes the main change: introducing a structured error model for SDK-wide standardization.
Linked Issues check ✅ Passed The PR implements core requirements from issue #423: introduces rac_error_model_t struct, maps error codes to categories, integrates into logging, and provides consistent error handling across native SDK layers.
Out of Scope Changes check ✅ Passed All changes directly support the error model objective: new error handling files, CMake integration, and logger enhancement are in-scope for introducing centralized error handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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";

@Siddhesh2377
Copy link
Copy Markdown
Collaborator

@Shalini828

@Siddhesh2377
Copy link
Copy Markdown
Collaborator

@shubhammalhotra28 can u marge ??? i did a commit so i am unable to merge the pr

Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
sdk/runanywhere-commons/src/core/rac_error_model.cpp (2)

6-8: Comment inconsistency: "Internal Helper" vs public API.

The comment labels rac_error_category as an "Internal Helper," but according to the header file (rac_error_model.h), this function is part of the public API. Consider updating the comment to reflect its public status or making the function static if it's truly internal.

🤖 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 above rac_error_category incorrectly calls it an "Internal Helper"
despite rac_error_model.h exposing it as part of the public API; either update
the comment to indicate it's a public API function (e.g., "Public API: Determine
Category from Error Code Range") to match the header, or if it should be
internal, make the function static and remove/adjust its public declaration in
rac_error_model.h so the implementation and header agree; locate the
rac_error_category definition and change the comment or alter the function
visibility accordingly.

4-4: Unused include: <string.h>

This header is included but no string functions (like strcmp, strlen, etc.) are used in this file. Consider removing it.

 `#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 inclusion "<string.h>" from rac_error_model.cpp; locate the
top-of-file include line and delete it (no string.h functions are used in this
file), leaving only the necessary headers for the RAC error model
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@sdk/runanywhere-commons/src/core/rac_error_model.cpp`:
- Around line 9-34: Add a "Server" category in rac_error_category() covering the
server codes (add a range for -206 through -200 returning "Server") and add
corresponding case entries in rac_error_message() for the server constants
(RAC_ERROR_SERVER_ALREADY_RUNNING ... RAC_ERROR_SERVER_TOO_MANY_REQUESTS) with
appropriate text; also close the structural gap at -390..-399 by expanding or
adjusting the ModuleService range in rac_error_category() (e.g., change its
range to cover -499 through -390 or add an explicit mapping for -399..-390) so
no codes fall through to "Unknown".

---

Nitpick comments:
In `@sdk/runanywhere-commons/src/core/rac_error_model.cpp`:
- Around line 6-8: The comment above rac_error_category incorrectly calls it an
"Internal Helper" despite rac_error_model.h exposing it as part of the public
API; either update the comment to indicate it's a public API function (e.g.,
"Public API: Determine Category from Error Code Range") to match the header, or
if it should be internal, make the function static and remove/adjust its public
declaration in rac_error_model.h so the implementation and header agree; locate
the rac_error_category definition and change the comment or alter the function
visibility accordingly.
- Line 4: Remove the unused C header inclusion "<string.h>" from
rac_error_model.cpp; locate the top-of-file include line and delete it (no
string.h functions are used in this file), leaving only the necessary headers
for the RAC error model implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93cada9c-0820-44cc-a126-99196348813e

📥 Commits

Reviewing files that changed from the base of the PR and between 7261465 and 4170e15.

📒 Files selected for processing (1)
  • sdk/runanywhere-commons/src/core/rac_error_model.cpp

Comment on lines +9 to +34
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";

if (code == RAC_SUCCESS) return "Success";

return "Unknown";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find all RAC_ERROR definitions and their values to verify complete coverage

echo "=== Error codes from rac_error.h ==="
rg -n '#define\s+RAC_ERROR_\w+\s+\(\(rac_result_t\)-[0-9]+\)' --type=cpp --type=c

echo ""
echo "=== Server error codes from rac_server.h ==="
rg -n 'RAC_ERROR_SERVER' --type=cpp --type=c -A1

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 5923


🏁 Script executed:

# Get the actual rac_error_model.cpp file to confirm function implementation
cat -n sdk/runanywhere-commons/src/core/rac_error_model.cpp | head -50

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 2365


🏁 Script executed:

# Check rac_error.cpp for message mappings of server and other codes
rg -n "RAC_ERROR_SERVER|case -15[0-9]|case -20[0-9]" sdk/runanywhere-commons/src/core/rac_error.cpp -A1 | head -40

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 163


🏁 Script executed:

# Check rac_error.cpp for all case statements related to server and uncovered codes
rg -n "case RAC_ERROR_SERVER|case -15[0-9]|case -20[0-9]|case -3[89][0-9]|case -40[0-9]" sdk/runanywhere-commons/src/core/rac_error.cpp

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 113


🏁 Script executed:

# Also check for any message mapping function to understand coverage
rg -n "rac_error_message" sdk/runanywhere-commons/src/core/rac_error.cpp | head -5

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 133


🏁 Script executed:

# Get the full rac_error_message function to see all case statements
sed -n '22,200p' sdk/runanywhere-commons/src/core/rac_error.cpp

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 7953


🏁 Script executed:

# Continue reading rac_error.cpp to see all case statements
sed -n '200,400p' sdk/runanywhere-commons/src/core/rac_error.cpp

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 7477


🏁 Script executed:

# Also search for any server error code definitions in rac_error.cpp
rg -n "RAC_ERROR_SERVER" sdk/runanywhere-commons/src/core/rac_error.cpp

Repository: RunanywhereAI/runanywhere-sdks

Length of output: 113


Server error codes (-200 to -206) missing from both category mapping and message definitions.

Server error codes defined in rac_server.h (RAC_ERROR_SERVER_ALREADY_RUNNING -200 through RAC_ERROR_SERVER_TOO_MANY_REQUESTS -206) are not covered in rac_error_category() and lack message mappings in rac_error_message(). They fall in the gap between Network (-179 to -150) and Storage (-219 to -180), causing both the category and message to return "Unknown".

Additionally, there is a structural gap at -390 to -399 (between Cancellation and ModuleService).

Suggested fix for Server category
     if (code >= -179 && code <= -150) return "Network";
+    if (code >= -209 && code <= -200) return "Server";
     if (code >= -219 && code <= -180) return "Storage";

Also add corresponding case statements in rac_error_message() for the six server codes.

🤖 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 9 - 34,
Add a "Server" category in rac_error_category() covering the server codes (add a
range for -206 through -200 returning "Server") and add corresponding case
entries in rac_error_message() for the server constants
(RAC_ERROR_SERVER_ALREADY_RUNNING ... RAC_ERROR_SERVER_TOO_MANY_REQUESTS) with
appropriate text; also close the structural gap at -390..-399 by expanding or
adjusting the ModuleService range in rac_error_category() (e.g., change its
range to cover -499 through -390 or add an explicit mapping for -399..-390) so
no codes fall through to "Unknown".

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

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