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/errors/errors.go b/internal/errors/errors.go
index e22035e..db1005d 100644
--- a/internal/errors/errors.go
+++ b/internal/errors/errors.go
@@ -7,6 +7,8 @@
import (
"fmt"
+
+ "google.golang.org/protobuf/internal/detrand"
)
// New formats a string according to the format specifier and arguments and
@@ -22,7 +24,16 @@
type prefixError struct{ s string }
-func (e *prefixError) Error() string { return "proto: " + e.s }
+var prefix = func() string {
+ if detrand.Bool() {
+ return "proto: "
+ }
+ return "proto: "
+}()
+
+func (e *prefixError) Error() string {
+ return prefix + e.s
+}
func InvalidUTF8(name string) error {
return New("field %v contains invalid UTF-8", name)