Browse Source

reflect/protoreflect: print unknown number in String methods

Preserving the unknown enum in the String method helps errors
produced by reflect/protodesc be more informative.

Change-Id: I8efb09cb3c744bf4483b310053df7686da540387
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/183699
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai 6 years ago
parent
commit
1ffc47f77e
1 changed files with 7 additions and 6 deletions
  1. 7 6
      reflect/protoreflect/proto.go

+ 7 - 6
reflect/protoreflect/proto.go

@@ -27,6 +27,7 @@
 package protoreflect
 
 import (
+	"fmt"
 	"regexp"
 	"strings"
 
@@ -69,7 +70,7 @@ func (s Syntax) String() string {
 	case Proto3:
 		return "proto3"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", s)
 	}
 }
 
@@ -81,7 +82,7 @@ func (s Syntax) GoString() string {
 	case Proto3:
 		return "Proto3"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", s)
 	}
 }
 
@@ -117,7 +118,7 @@ func (c Cardinality) String() string {
 	case Repeated:
 		return "repeated"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", c)
 	}
 }
 
@@ -131,7 +132,7 @@ func (c Cardinality) GoString() string {
 	case Repeated:
 		return "Repeated"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", c)
 	}
 }
 
@@ -217,7 +218,7 @@ func (k Kind) String() string {
 	case GroupKind:
 		return "group"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", k)
 	}
 }
 
@@ -261,7 +262,7 @@ func (k Kind) GoString() string {
 	case GroupKind:
 		return "GroupKind"
 	default:
-		return "<unknown>"
+		return fmt.Sprintf("<unknown:%d>", k)
 	}
 }