Skip to content

Commit 2fe278d

Browse files
Better errors
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
1 parent b759d22 commit 2fe278d

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

internal/signermsgs/en_error_messges.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ var (
107107
MsgInvalidNumberString = ffe("FF22088", "Invalid integer string '%s'")
108108
MsgInvalidIntPrecisionLoss = ffe("FF22089", "String %s cannot be converted to integer without losing precision")
109109
MsgInvalidUint64PrecisionLoss = ffe("FF22090", "String %s cannot be converted to a uint64 without losing precision")
110+
MsgInvalidJSONTypeForBigInt = ffe("FF22091", "JSON parsed '%T' cannot be converted to an integer")
110111
)

pkg/ethtypes/hexinteger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (h HexInteger) MarshalJSON() ([]byte, error) {
3636
}
3737

3838
func (h *HexInteger) UnmarshalJSON(b []byte) error {
39-
bi, err := UnmarshalBigInt(b)
39+
bi, err := UnmarshalBigInt(context.Background(), b)
4040
if err != nil {
4141
return err
4242
}

pkg/ethtypes/hexinteger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestHexIntegerBadType(t *testing.T) {
9090
}`
9191

9292
err := json.Unmarshal([]byte(testData), &testStruct)
93-
assert.Regexp(t, "unable to parse integer", err)
93+
assert.Regexp(t, "FF22091", err)
9494
}
9595

9696
func TestHexIntegerBadJSON(t *testing.T) {

pkg/ethtypes/hexuint64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (h HexUint64) MarshalJSON() ([]byte, error) {
4040
}
4141

4242
func (h *HexUint64) UnmarshalJSON(b []byte) error {
43-
bi, err := UnmarshalBigInt(b)
43+
bi, err := UnmarshalBigInt(context.Background(), b)
4444
if err != nil {
4545
return err
4646
}

pkg/ethtypes/hexuint64_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestHexUint64BadType(t *testing.T) {
8787
}`
8888

8989
err := json.Unmarshal([]byte(testData), &testStruct)
90-
assert.Regexp(t, "unable to parse integer", err)
90+
assert.Regexp(t, "FF22091", err)
9191
}
9292

9393
func TestHexUint64BadJSON(t *testing.T) {

pkg/ethtypes/integer_parsing.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"context"
2222
"encoding/json"
23-
"fmt"
2423
"math/big"
2524

2625
"github.com/hyperledger/firefly-common/pkg/i18n"
@@ -49,7 +48,7 @@ func BigIntegerFromString(ctx context.Context, s string) (*big.Int, error) {
4948
return i, nil
5049
}
5150

52-
func UnmarshalBigInt(b []byte) (*big.Int, error) {
51+
func UnmarshalBigInt(ctx context.Context, b []byte) (*big.Int, error) {
5352
var i interface{}
5453
d := json.NewDecoder(bytes.NewReader(b))
5554
d.UseNumber()
@@ -63,6 +62,6 @@ func UnmarshalBigInt(b []byte) (*big.Int, error) {
6362
case string:
6463
return BigIntegerFromString(context.Background(), i)
6564
default:
66-
return nil, fmt.Errorf("unable to parse integer from type %T", i)
65+
return nil, i18n.NewError(ctx, signermsgs.MsgInvalidJSONTypeForBigInt, i)
6766
}
6867
}

0 commit comments

Comments
 (0)