Skip to content

Commit

Permalink
Fixes for verif tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Jul 16, 2024
1 parent e6f1b63 commit 3588cd2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,23 @@ func (j jsonCodec) OutputPayload() *OutputPayload {
}

func (j jsonCodec) Unmarshal(data []byte, input any) (err error) {
return json.Unmarshal(data, &input)
switch input.(type) {
case *Void:
// special case; don't try and unmarshal into Void
return nil
default:
return json.Unmarshal(data, input)
}
}

func (j jsonCodec) Marshal(output any) ([]byte, error) {
return json.Marshal(output)
switch output.(type) {
case Void:
// special case; send no data
return nil, nil
default:
return json.Marshal(output)
}
}

type protoCodec struct{}
Expand Down
3 changes: 2 additions & 1 deletion example/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"math/big"

Expand All @@ -24,7 +25,7 @@ var bigCounter = restate.
}

bytes, err := restate.GetAs[[]byte](ctx, "counter", restate.WithBinary)
if err != nil && err != restate.ErrKeyNotFound {
if err != nil && !errors.Is(err, restate.ErrKeyNotFound) {
return "", err
}
newCount := big.NewInt(0).Add(big.NewInt(0).SetBytes(bytes), delta)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/restatedev/sdk-go

go 1.21.0

toolchain go1.21.12

require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
Expand Down
2 changes: 1 addition & 1 deletion internal/state/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d decodingResponseFuture) Response(output any) (err error) {
}

if err := d.options.Codec.Unmarshal(bytes, output); err != nil {
return errors.NewTerminalError(fmt.Errorf("failed to unmarshal Call response into O: %w", err))
return errors.NewTerminalError(fmt.Errorf("failed to unmarshal Call response into output: %w", err))
}

return nil
Expand Down

0 comments on commit 3588cd2

Please sign in to comment.