all: make error messages unstable
Use internal/detrand in the construction of our error messages.
This alters whether there is one or two spaces following the "proto:" prefix.
While it is easy for users to still work around this mutation,
sit at least forces them to write test infrastructure to more fuzzily
match on error strings.
Change-Id: I4ddca717526ee3fc4dbb1e0b36cfca8c6e0df36d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/194038
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/cmd/pbdump/pbdump.go b/internal/cmd/pbdump/pbdump.go
index 71912b1..62e3a27 100644
--- a/internal/cmd/pbdump/pbdump.go
+++ b/internal/cmd/pbdump/pbdump.go
@@ -19,6 +19,7 @@
"google.golang.org/protobuf/internal/encoding/pack"
"google.golang.org/protobuf/internal/encoding/wire"
+ "google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
@@ -174,7 +175,7 @@
n, _ := strconv.ParseInt(s[:i], 10, 32)
num := wire.Number(n)
if num < wire.MinValidNumber || wire.MaxValidNumber < num {
- return fmt.Errorf("invalid field: %v", prefix)
+ return errors.New("invalid field: %v", prefix)
}
s = strings.TrimPrefix(s[i:], ".")
@@ -184,7 +185,7 @@
}
if len(s) == 0 {
if fs[num].kind.IsValid() {
- return fmt.Errorf("field %v already set as %v type", prefix, fs[num].kind)
+ return errors.New("field %v already set as %v type", prefix, fs[num].kind)
}
fs[num].kind = k
}
@@ -195,7 +196,7 @@
// Verify that only messages or groups can have sub-fields.
k2 := fs[num].kind
if k2 > 0 && k2 != protoreflect.MessageKind && k2 != protoreflect.GroupKind && len(fs[num].sub) > 0 {
- return fmt.Errorf("field %v of %v type cannot have sub-fields", prefix, k2)
+ return errors.New("field %v of %v type cannot have sub-fields", prefix, k2)
}
return nil
}