-
Notifications
You must be signed in to change notification settings - Fork 352
Introduce Centralized Typed Error Model Across SDKs #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused include -
Suggested change
Prompt To Fix With AIThis 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
Prompt To Fix With AIThis 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 -A1Repository: 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 -50Repository: 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 -40Repository: 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.cppRepository: 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 -5Repository: 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.cppRepository: 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.cppRepository: 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.cppRepository: 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 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 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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
Prompt To Fix With AI
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!