Przeglądaj źródła

Use fmt.Errorf instead of errors.New (#481)

The %v verb in Errorf automatically calls the String method.
This is safer than manually calling reflect.Type.String since
the reflect.Type may be nil.
Joe Tsai 8 lat temu
rodzic
commit
572071ce41
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      proto/extensions.go

+ 1 - 1
proto/extensions.go

@@ -218,7 +218,7 @@ func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
 		pbi = ea.extendableProtoV1
 	}
 	if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b {
-		return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String())
+		return fmt.Errorf("proto: bad extended type; %v does not extend %v", b, a)
 	}
 	// Check the range.
 	if !isExtensionField(pb, extension.Field) {