Skip to content

Commit 6a6e8b7

Browse files
authored
fix(sdk-go): Catch nil value early when converting interface to var val (#1271)
1 parent 705a48f commit 6a6e8b7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sdk-go/littlehorse/lh_variables.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package littlehorse
33
import (
44
"encoding/base64"
55
"encoding/json"
6-
"github.com/littlehorse-enterprises/littlehorse/sdk-go/lhproto"
76
"reflect"
87
"strconv"
8+
9+
"github.com/littlehorse-enterprises/littlehorse/sdk-go/lhproto"
910
)
1011

1112
func StrToVarVal(input string, varType lhproto.VariableType) (*lhproto.VariableValue, error) {
@@ -143,6 +144,10 @@ func GetVarType(thing interface{}) *lhproto.VariableType {
143144
}
144145

145146
func InterfaceToVarVal(someInterface interface{}) (*lhproto.VariableValue, error) {
147+
if someInterface == nil {
148+
return &lhproto.VariableValue{}, nil
149+
}
150+
146151
out := &lhproto.VariableValue{}
147152
var err error
148153

@@ -152,9 +157,6 @@ func InterfaceToVarVal(someInterface interface{}) (*lhproto.VariableValue, error
152157
}
153158

154159
isPtr, _ := GetIsPtrAndType(reflect.TypeOf(someInterface))
155-
if someInterface == nil {
156-
return &lhproto.VariableValue{}, nil
157-
}
158160

159161
var actualThing interface{}
160162
if isPtr {

0 commit comments

Comments
 (0)