Przeglądaj źródła

proto: return more useful error message in SetExtension (#685)

Including the types that are mismatched, rather than just stating that there was a type mismatch makes the error easier to debug and fix.
dasmdasm 7 lat temu
rodzic
commit
9e2f3b8f55
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      proto/extensions.go

+ 1 - 1
proto/extensions.go

@@ -488,7 +488,7 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
 	}
 	typ := reflect.TypeOf(extension.ExtensionType)
 	if typ != reflect.TypeOf(value) {
-		return errors.New("proto: bad extension value type")
+		return fmt.Errorf("proto: bad extension value type. got: %T, want: %T", value, extension.ExtensionType)
 	}
 	// nil extension values need to be caught early, because the
 	// encoder can't distinguish an ErrNil due to a nil extension