Skip to content

Commit

Permalink
fix(sdk-go): Catch nil value early when converting interface to var…
Browse files Browse the repository at this point in the history
… val (#1271)
  • Loading branch information
Snarr authored Jan 29, 2025
1 parent 705a48f commit 6a6e8b7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sdk-go/littlehorse/lh_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package littlehorse
import (
"encoding/base64"
"encoding/json"
"github.com/littlehorse-enterprises/littlehorse/sdk-go/lhproto"
"reflect"
"strconv"

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

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

func InterfaceToVarVal(someInterface interface{}) (*lhproto.VariableValue, error) {
if someInterface == nil {
return &lhproto.VariableValue{}, nil
}

out := &lhproto.VariableValue{}
var err error

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

isPtr, _ := GetIsPtrAndType(reflect.TypeOf(someInterface))
if someInterface == nil {
return &lhproto.VariableValue{}, nil
}

var actualThing interface{}
if isPtr {
Expand Down

0 comments on commit 6a6e8b7

Please sign in to comment.