diff --git a/sdk-go/littlehorse/lh_errors.go b/sdk-go/littlehorse/lh_errors.go index 4dd9610a0..867bb4132 100644 --- a/sdk-go/littlehorse/lh_errors.go +++ b/sdk-go/littlehorse/lh_errors.go @@ -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 } diff --git a/sdk-go/littlehorse/lh_variables.go b/sdk-go/littlehorse/lh_variables.go index 040b966f2..432f12b9f 100644 --- a/sdk-go/littlehorse/lh_variables.go +++ b/sdk-go/littlehorse/lh_variables.go @@ -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 diff --git a/sdk-go/littlehorse/task_worker_internal.go b/sdk-go/littlehorse/task_worker_internal.go index c2591bf18..bfd0988d5 100644 --- a/sdk-go/littlehorse/task_worker_internal.go +++ b/sdk-go/littlehorse/task_worker_internal.go @@ -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 {