Skip to content

Commit

Permalink
Add Type Name to error message in CBOR conversion (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: CodingVoid <[email protected]>

Co-authored-by: Maximilian Brune <[email protected]>
  • Loading branch information
CodingVoid and CodingVoid authored Jun 24, 2022
1 parent 6261c52 commit 7759347
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func arrayToCBOR(a reflect.Value) ([]byte, error) {

switch a.Len() {
case 0:
return nil, errors.New("array MUST NOT be 0-length")
return nil, fmt.Errorf("array of %s MUST NOT be 0-length", a.Type().Name())
case 1:
return em.Marshal(a.Index(0).Interface())
default:
Expand Down
2 changes: 1 addition & 1 deletion files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestFiles_DoNotEncodeZeroLength(t *testing.T) {
tv := Files{}

_, err := em.Marshal(tv)
assert.EqualError(t, err, "array MUST NOT be 0-length")
assert.EqualError(t, err, "array of Files MUST NOT be 0-length")
}

func TestFiles_RoundtripEncodeOne(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion processes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestProcesses_MarshalCBOR(t *testing.T) {
name: "zero elements",
tv: Processes{},
expected: []byte("__ignored__"),
expectedErr: errors.New("array MUST NOT be 0-length"),
expectedErr: errors.New("array of Processes MUST NOT be 0-length"),
},
{
name: "one element (encodes to scalar)",
Expand Down

0 comments on commit 7759347

Please sign in to comment.