Skip to content
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

feat(sdk-go): Allow users to pass any content to LHTaskException #1216

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
8 changes: 5 additions & 3 deletions sdk-go/littlehorse/lh_errors.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package littlehorse

import "github.com/littlehorse-enterprises/littlehorse/sdk-go/lhproto"

type LHTaskException struct {
Name string
Message string
Content *lhproto.VariableValue
Content interface{}
}

func (e *LHTaskException) Error() string {
return e.Message
}
5 changes: 5 additions & 0 deletions sdk-go/littlehorse/lh_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func InterfaceToVarVal(someInterface interface{}) (*lhproto.VariableValue, error
out := &lhproto.VariableValue{}
var err error

interfaceAsVarVal, isVarVal := someInterface.(*lhproto.VariableValue)
if isVarVal {
return interfaceAsVarVal, nil
}

isPtr, _ := GetIsPtrAndType(reflect.TypeOf(someInterface))
if someInterface == nil {
return &lhproto.VariableValue{}, nil
Expand Down
14 changes: 13 additions & 1 deletion sdk-go/littlehorse/task_worker_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,23 @@ func (m *serverConnectionManager) doTaskHelper(task *lhproto.ScheduledTask) *lhp
if errorReflect.Interface() != nil {
// Check if the error is an LHTaskException
if lhtErr, ok := errorReflect.Interface().(*LHTaskException); ok {
taskErrContent, err := InterfaceToVarVal(lhtErr.Content)

if err != nil {
msg := "LH_SDK_GO_ERR: Failed to serialize task error content passed from task worker: " + err.Error()

taskErrContent = &lhproto.VariableValue{
Value: &lhproto.VariableValue_Str{
Str: msg,
},
}
}

taskResult.Result = &lhproto.ReportTaskRun_Exception{
Exception: &lhproto.LHTaskException{
Name: lhtErr.Name,
Message: lhtErr.Message,
Content: lhtErr.Content,
Content: taskErrContent,
},
}
} else {
Expand Down
Loading