Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1003

bson handling of type declaration should be more clear

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:

      I wrote the following test which reflects a problem that we ran into during our migration from mgobson. It was easy to amend our code to avoid this situation, but the error message that you get from Unmarshal in this situation is "cannot decode binary into a slice", which isn't super intuitive, particularly without context, and because the "First" field is what a developer would think of as a slice.

      func TestBinarySlice(t *testing.T) {
      	type raw []byte
      	type fob struct {
      		First raw `bson:"first"`
      	}
      
      	inter := M{
      		"first": []byte("foo"),
      	}
      
      	data, err := Marshal(inter)
      	require.NoError(t, err)
      
      	out := fob{}
      
      	err = Unmarshal(data, &out)
      	require.NoError(t, err)
      
      	require.Equal(t, string(out.First), "foo")
      }
      

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            sam.kleinman Sam Kleinman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: