Skip to content

Commit

Permalink
better errors
Browse files Browse the repository at this point in the history
Keep error messages consistent and return the upper bound.
  • Loading branch information
magiconair committed Mar 14, 2022
1 parent b703000 commit 3688c80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ua/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func decodeSlice(b []byte, val reflect.Value, name string) (int, error) {
}

if n > math.MaxInt32 {
return buf.Pos(), errors.Errorf("array too large: %d", n)
return buf.Pos(), errors.Errorf("array too large: %d > %d", n, math.MaxInt32)
}

// elemType is the type of the slice elements
Expand Down Expand Up @@ -178,11 +178,11 @@ func decodeArray(b []byte, val reflect.Value, name string) (int, error) {
}

if n > math.MaxInt32 {
return buf.Pos(), errors.Errorf("array too large: %d", n)
return buf.Pos(), errors.Errorf("array too large: %d > %d", n, math.MaxInt32)
}

if n > uint32(val.Len()) {
return buf.Pos(), errors.Errorf("array too large, it does not fit into the type: encoded array len = %d, array len = %d", n, val.Len())
return buf.Pos(), errors.Errorf("array too large: %d > %d", n, val.Len())
}

// elemType is the type of the slice elements
Expand Down
2 changes: 1 addition & 1 deletion ua/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func writeArray(val reflect.Value, name string) ([]byte, error) {
buf := NewBuffer(nil)

if val.Len() > math.MaxInt32 {
return nil, errors.Errorf("array too large")
return nil, errors.Errorf("array too large: %d > %d", val.Len(), math.MaxInt32)
}

buf.WriteUint32(uint32(val.Len()))
Expand Down

0 comments on commit 3688c80

Please sign in to comment.