Skip to content

Commit

Permalink
[pkg/ottl] Return nil on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rnishtala-sumo committed Jun 1, 2023
1 parent 40d180a commit 3cc5a64
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/ottl/ottlfuncs/func_fnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func FNVHashString[K any](target ottl.StringGetter[K]) (ottl.ExprFunc[K], error)
hash := fnv.New64a()
_, err1 := hash.Write([]byte(val))
if err1 != nil {
return val, err1
return nil, err1
}
hashValue := hash.Sum64()
return hashValue, nil
return int64(hashValue), nil
}, nil
}
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/func_fnv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_FNV(t *testing.T) {
{
name: "string",
value: "hello world",
expected: uint64(8618312879776256743),
expected: int64(8618312879776256743),
},
{
name: "empty string",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ottl/ottlfuncs/func_sha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"crypto/sha1" // #nosec
"encoding/hex"
"fmt"
"io"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
)
Expand Down Expand Up @@ -44,8 +43,9 @@ func SHA1HashString[K any](target ottl.StringGetter[K]) (ottl.ExprFunc[K], error
}

hash := sha1.New() // #nosec
if _, err := io.WriteString(hash, val); err != nil {
return val, err
_, err1 := hash.Write([]byte(val))
if err1 != nil {
return nil, err1
}
hashValue := hex.EncodeToString(hash.Sum(nil))
return hashValue, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/ottl/ottlfuncs/func_sha256.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func SHA256HashString[K any](target ottl.StringGetter[K]) (ottl.ExprFunc[K], err
hash := sha256.New()
_, err1 := hash.Write([]byte(val))
if err1 != nil {
return val, err1
return nil, err1
}
hashValue := hex.EncodeToString(hash.Sum(nil))
fmt.Print(hashValue)
return hashValue, nil
}, nil
}

0 comments on commit 3cc5a64

Please sign in to comment.