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
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!

44 changes: 44 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,44 @@
#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.


// ------------------------------------------------------------
// 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 >= -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 +28
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.


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

return "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