Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/runanywhere-commons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ set(RAC_CORE_SOURCES
src/core/sdk_state.cpp
src/core/rac_structured_error.cpp
src/core/capabilities/lifecycle_manager.cpp
src/core/rac_error_model.cpp
)

# Infrastructure sources - registry, model management, network, telemetry
Expand Down
36 changes: 36 additions & 0 deletions sdk/runanywhere-commons/include/rac/core/rac_error_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef RAC_ERROR_MODEL_H
#define RAC_ERROR_MODEL_H

#include "rac/core/rac_error.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Structured error model for RunAnywhere SDKs
*
* This wraps existing rac_result_t codes into a typed,
* structured error representation for cross-SDK consistency.
*/
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) */
} rac_error_model_t;

/**
* @brief Create structured error model from error code
*/
rac_error_model_t rac_make_error_model(rac_result_t code);

/**
* @brief Get error category string from error code
*/
const char* rac_error_category(rac_result_t code);

#ifdef __cplusplus
}
#endif

#endif // RAC_ERROR_MODEL_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.

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!

45 changes: 45 additions & 0 deletions sdk/runanywhere-commons/src/core/rac_error_model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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.


// ------------------------------------------------------------
// Internal Helper: Determine Category from Error Code Range
// ------------------------------------------------------------
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";
Comment on lines +9 to +29
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.


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

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


// ------------------------------------------------------------
// Public API: Create Structured Error Model
// ------------------------------------------------------------
rac_error_model_t rac_make_error_model(rac_result_t code) {
rac_error_model_t model;
model.code = code;
model.message = rac_error_message(code);
model.category = rac_error_category(code);
return model;
}
6 changes: 5 additions & 1 deletion sdk/runanywhere-commons/src/core/rac_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstring>
#include <mutex>

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

// =============================================================================
Expand Down Expand Up @@ -154,7 +155,10 @@ void log_to_stderr(rac_log_level_t level, const char* category, const char* mess
fprintf(stream, ", func=%s", metadata->function);
}
if (metadata->error_code != 0) {
fprintf(stream, ", error_code=%d", metadata->error_code);
rac_error_model_t err = rac_make_error_model((rac_result_t)metadata->error_code);
fprintf(stream, ", error_code=%d", err.code);
fprintf(stream, ", error_category=%s", err.category);
fprintf(stream, ", error_message=%s", err.message);
}
if (metadata->model_id) {
fprintf(stream, ", model=%s", metadata->model_id);
Expand Down