-
Notifications
You must be signed in to change notification settings - Fork 4
Surface errors in invoke actions #645
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
Conversation
WalkthroughAdds error handling to ActionInvokeTaskHandler: when an invoked action returns BATON_ACTION_STATUS_FAILED, the code extracts an "error" field from the response, logs it, and finishes the task with that error. The fmt package was added for error formatting. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/tasks/c1api/actions.go`:
- Around line 142-148: The error extraction logic when resp.GetStatus() ==
v2.BatonActionStatus_BATON_ACTION_STATUS_FAILED can overwrite the default error
with an empty string because GetStringValue() returns "" for non-string kinds;
update the guard in the block that checks resp.GetResponse() and
resp.GetResponse().GetFields() to verify the "error" field exists, is non-nil,
and is of string kind (or has a non-empty string) before assigning errMsg from
resp.GetResponse().GetFields()["error"].GetStringValue(); if the field is not a
string or is empty, leave errMsg as the default (or fall back to a generic
formatted value) so you never return a blank error. Ensure you reference
resp.GetResponse(), resp.GetResponse().GetFields(), and the "error" field when
adding these checks.
| // Check if the action itself failed and propagate the error | ||
| if resp.GetStatus() == v2.BatonActionStatus_BATON_ACTION_STATUS_FAILED { | ||
| errMsg := "action failed" | ||
| if resp.GetResponse() != nil && resp.GetResponse().GetFields() != nil { | ||
| if errField, ok := resp.GetResponse().GetFields()["error"]; ok { | ||
| errMsg = errField.GetStringValue() | ||
| } |
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.
Guard against non-string/empty error fields so you don’t return a blank error.
GetStringValue() returns "" for non-string kinds, which overrides the default and can yield an empty error message. Also handle potential nil values defensively.
💡 Suggested fix
- if errField, ok := resp.GetResponse().GetFields()["error"]; ok {
- errMsg = errField.GetStringValue()
- }
+ if errField, ok := resp.GetResponse().GetFields()["error"]; ok && errField != nil {
+ if s := errField.GetStringValue(); s != "" {
+ errMsg = s
+ } else {
+ errMsg = errField.String()
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Check if the action itself failed and propagate the error | |
| if resp.GetStatus() == v2.BatonActionStatus_BATON_ACTION_STATUS_FAILED { | |
| errMsg := "action failed" | |
| if resp.GetResponse() != nil && resp.GetResponse().GetFields() != nil { | |
| if errField, ok := resp.GetResponse().GetFields()["error"]; ok { | |
| errMsg = errField.GetStringValue() | |
| } | |
| // Check if the action itself failed and propagate the error | |
| if resp.GetStatus() == v2.BatonActionStatus_BATON_ACTION_STATUS_FAILED { | |
| errMsg := "action failed" | |
| if resp.GetResponse() != nil && resp.GetResponse().GetFields() != nil { | |
| if errField, ok := resp.GetResponse().GetFields()["error"]; ok && errField != nil { | |
| if s := errField.GetStringValue(); s != "" { | |
| errMsg = s | |
| } else { | |
| errMsg = errField.String() | |
| } | |
| } |
🤖 Prompt for AI Agents
In `@pkg/tasks/c1api/actions.go` around lines 142 - 148, The error extraction
logic when resp.GetStatus() == v2.BatonActionStatus_BATON_ACTION_STATUS_FAILED
can overwrite the default error with an empty string because GetStringValue()
returns "" for non-string kinds; update the guard in the block that checks
resp.GetResponse() and resp.GetResponse().GetFields() to verify the "error"
field exists, is non-nil, and is of string kind (or has a non-empty string)
before assigning errMsg from
resp.GetResponse().GetFields()["error"].GetStringValue(); if the field is not a
string or is empty, leave errMsg as the default (or fall back to a generic
formatted value) so you never return a blank error. Ensure you reference
resp.GetResponse(), resp.GetResponse().GetFields(), and the "error" field when
adding these checks.
pkg/tasks/c1api/actions.go
Outdated
| errMsg = errField.GetStringValue() | ||
| } | ||
| } | ||
| l.Error("ActionInvoke failed", zap.String("error", errMsg), zap.Any("resp", resp)) |
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.
are we ok with zap.any in the sdk? i guess we already do it in the lines right below this 🤷
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.
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.
looks good!
gontzess
left a comment
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.
lgtm
Previously it would just fail opaquely with no additional info in the task log
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.