@@ -89,7 +89,7 @@ const (
8989 BinaryUserDefined byte = 0x80
9090)
9191
92- // A value implementing the bson.Getter interface will have its GetBSON
92+ // Getter interface: a value implementing the bson.Getter interface will have its GetBSON
9393// method called when the given value has to be marshalled, and the result
9494// of this method will be marshaled in place of the actual object.
9595//
@@ -99,12 +99,12 @@ type Getter interface {
9999 GetBSON () (interface {}, error )
100100}
101101
102- // A value implementing the bson.Setter interface will receive the BSON
102+ // Setter interface: a value implementing the bson.Setter interface will receive the BSON
103103// value via the SetBSON method during unmarshaling, and the object
104104// itself will not be changed as usual.
105105//
106106// If setting the value works, the method should return nil or alternatively
107- // bson.SetZero to set the respective field to its zero value (nil for
107+ // bson.ErrSetZero to set the respective field to its zero value (nil for
108108// pointer types). If SetBSON returns a value of type bson.TypeError, the
109109// BSON value will be omitted from a map or slice being decoded and the
110110// unmarshalling will continue. If it returns any other non-nil error, the
@@ -130,10 +130,10 @@ type Setter interface {
130130 SetBSON (raw Raw ) error
131131}
132132
133- // SetZero may be returned from a SetBSON method to have the value set to
133+ // ErrSetZero may be returned from a SetBSON method to have the value set to
134134// its respective zero value. When used in pointer values, this will set the
135135// field to nil rather than to the pre-allocated value.
136- var SetZero = errors .New ("set to zero" )
136+ var ErrSetZero = errors .New ("set to zero" )
137137
138138// M is a convenient alias for a map[string]interface{} map, useful for
139139// dealing with BSON in a native way. For instance:
@@ -189,7 +189,7 @@ type Raw struct {
189189// documents in general.
190190type RawD []RawDocElem
191191
192- // See the RawD type.
192+ // RawDocElem elements of RawD type.
193193type RawDocElem struct {
194194 Name string
195195 Value Raw
@@ -199,7 +199,7 @@ type RawDocElem struct {
199199// long. MongoDB objects by default have such a property set in their "_id"
200200// property.
201201//
202- // http://www.mongodb.org/display/DOCS/Object+IDs
202+ // http://www.mongodb.org/display/DOCS/Object+Ids
203203type ObjectId string
204204
205205// ObjectIdHex returns an ObjectId from the provided hex representation.
@@ -225,7 +225,7 @@ func IsObjectIdHex(s string) bool {
225225
226226// objectIdCounter is atomically incremented when generating a new ObjectId
227227// using NewObjectId() function. It's used as a counter part of an id.
228- var objectIdCounter uint32 = readRandomUint32 ()
228+ var objectIdCounter = readRandomUint32 ()
229229
230230// readRandomUint32 returns a random objectIdCounter.
231231func readRandomUint32 () uint32 {
@@ -333,12 +333,12 @@ func (id *ObjectId) UnmarshalJSON(data []byte) error {
333333 return nil
334334 }
335335 if len (data ) != 26 || data [0 ] != '"' || data [25 ] != '"' {
336- return errors . New ( fmt .Sprintf ("invalid ObjectId in JSON: %s" , string (data ) ))
336+ return fmt .Errorf ("invalid ObjectId in JSON: %s" , string (data ))
337337 }
338338 var buf [12 ]byte
339339 _ , err := hex .Decode (buf [:], data [1 :25 ])
340340 if err != nil {
341- return errors . New ( fmt .Sprintf ("invalid ObjectId in JSON: %s (%s)" , string (data ), err ) )
341+ return fmt .Errorf ("invalid ObjectId in JSON: %s (%s)" , string (data ), err )
342342 }
343343 * id = ObjectId (string (buf [:]))
344344 return nil
@@ -604,12 +604,12 @@ func Unmarshal(in []byte, out interface{}) (err error) {
604604 d := newDecoder (in )
605605 d .readDocTo (v )
606606 if d .i < len (d .in ) {
607- return errors .New ("Document is corrupted" )
607+ return errors .New ("document is corrupted" )
608608 }
609609 case reflect .Struct :
610- return errors .New ("Unmarshal can't deal with struct values. Use a pointer. " )
610+ return errors .New ("unmarshal can't deal with struct values. Use a pointer" )
611611 default :
612- return errors .New ("Unmarshal needs a map or a pointer to a struct. " )
612+ return errors .New ("unmarshal needs a map or a pointer to a struct" )
613613 }
614614 return nil
615615}
@@ -633,13 +633,15 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
633633 return & TypeError {v .Type (), raw .Kind }
634634 }
635635 case reflect .Struct :
636- return errors .New ("Raw Unmarshal can't deal with struct values. Use a pointer. " )
636+ return errors .New ("raw Unmarshal can't deal with struct values. Use a pointer" )
637637 default :
638- return errors .New ("Raw Unmarshal needs a map or a valid pointer. " )
638+ return errors .New ("raw Unmarshal needs a map or a valid pointer" )
639639 }
640640 return nil
641641}
642642
643+ // TypeError store details for type error occuring
644+ // during unmarshaling
643645type TypeError struct {
644646 Type reflect.Type
645647 Kind byte
0 commit comments