goprotobuf: GetExtension now returns a specific error when the requested extension is missing.
Also tidy up property parsing a little bit.
R=r
CC=golang-dev
http://codereview.appspot.com/5557044
diff --git a/proto/extensions.go b/proto/extensions.go
index d02cadc..9f840fa 100644
--- a/proto/extensions.go
+++ b/proto/extensions.go
@@ -41,6 +41,9 @@
"strconv"
)
+// ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message.
+var ErrMissingExtension = errors.New("proto: missing extension")
+
// ExtensionRange represents a range of message extensions for a protocol buffer.
// Used in code generated by the protocol compiler.
type ExtensionRange struct {
@@ -153,7 +156,7 @@
}
// GetExtension parses and returns the given extension of pb.
-// If the extension is not present it returns (nil, nil).
+// If the extension is not present it returns ErrMissingExtension.
func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
if err := checkExtensionTypes(pb, extension); err != nil {
return nil, err
@@ -161,7 +164,7 @@
e, ok := pb.ExtensionMap()[extension.Field]
if !ok {
- return nil, nil // not an error
+ return nil, ErrMissingExtension
}
if e.value != nil {
// Already decoded. Check the descriptor, though.