@@ -2,7 +2,6 @@ package maxminddb
2
2
3
3
import (
4
4
"encoding/binary"
5
- "fmt"
6
5
"math"
7
6
"math/big"
8
7
"reflect"
@@ -126,7 +125,7 @@ func (d *decoder) unmarshalBool(size uint, offset uint, result reflect.Value) (u
126
125
}
127
126
switch result .Kind () {
128
127
default :
129
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
128
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
130
129
case reflect .Bool :
131
130
result .SetBool (value )
132
131
return newOffset , nil
@@ -144,7 +143,7 @@ func (d *decoder) unmarshalBytes(size uint, offset uint, result reflect.Value) (
144
143
}
145
144
switch result .Kind () {
146
145
default :
147
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
146
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
148
147
case reflect .Slice :
149
148
result .SetBytes (value )
150
149
return newOffset , nil
@@ -165,7 +164,7 @@ func (d *decoder) unmarshalFloat32(size uint, offset uint, result reflect.Value)
165
164
166
165
switch result .Kind () {
167
166
default :
168
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
167
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
169
168
case reflect .Float32 , reflect .Float64 :
170
169
result .SetFloat (float64 (value ))
171
170
return newOffset , nil
@@ -186,7 +185,7 @@ func (d *decoder) unmarshalFloat64(size uint, offset uint, result reflect.Value)
186
185
}
187
186
switch result .Kind () {
188
187
default :
189
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
188
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
190
189
case reflect .Float32 , reflect .Float64 :
191
190
result .SetFloat (value )
192
191
return newOffset , nil
@@ -207,13 +206,13 @@ func (d *decoder) unmarshalInt32(size uint, offset uint, result reflect.Value) (
207
206
208
207
switch result .Kind () {
209
208
default :
210
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
209
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
211
210
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
212
211
result .SetInt (int64 (value ))
213
212
return newOffset , nil
214
213
case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 , reflect .Uintptr :
215
214
if value < 0 {
216
- return 0 , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
215
+ return 0 , newUnmarshalTypeError ( value , result .Type ())
217
216
}
218
217
result .SetUint (uint64 (value ))
219
218
return newOffset , nil
@@ -226,7 +225,7 @@ func (d *decoder) unmarshalInt32(size uint, offset uint, result reflect.Value) (
226
225
func (d * decoder ) unmarshalMap (size uint , offset uint , result reflect.Value ) (uint , error ) {
227
226
switch result .Kind () {
228
227
default :
229
- return 0 , fmt . Errorf ( "trying to unmarshal a map into %v " , result .Type ())
228
+ return 0 , newUnmarshalTypeError ( " map" , result .Type ())
230
229
case reflect .Struct :
231
230
return d .decodeStruct (size , offset , result )
232
231
case reflect .Map :
@@ -249,7 +248,7 @@ func (d *decoder) unmarshalSlice(size uint, offset uint, result reflect.Value) (
249
248
250
249
switch result .Kind () {
251
250
default :
252
- return 0 , fmt . Errorf ( "trying to unmarshal an array into %v " , result .Type ())
251
+ return 0 , newUnmarshalTypeError ( " array" , result .Type ())
253
252
case reflect .Slice :
254
253
return d .decodeSlice (size , offset , result )
255
254
case reflect .Interface :
@@ -270,7 +269,7 @@ func (d *decoder) unmarshalString(size uint, offset uint, result reflect.Value)
270
269
}
271
270
switch result .Kind () {
272
271
default :
273
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
272
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
274
273
case reflect .String :
275
274
result .SetString (value )
276
275
return newOffset , nil
@@ -292,7 +291,7 @@ func (d *decoder) unmarshalUint(size uint, offset uint, result reflect.Value, ui
292
291
293
292
switch result .Kind () {
294
293
default :
295
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
294
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
296
295
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
297
296
result .SetInt (int64 (value ))
298
297
return newOffset , nil
@@ -318,7 +317,7 @@ func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value)
318
317
// Currently this is reported as invalid
319
318
switch result .Kind () {
320
319
default :
321
- return newOffset , fmt . Errorf ( "trying to unmarshal %v into %v" , value , result .Type ())
320
+ return newOffset , newUnmarshalTypeError ( value , result .Type ())
322
321
case reflect .Struct :
323
322
result .Set (reflect .ValueOf (* value ))
324
323
return newOffset , nil
0 commit comments