internal: improve use of detrand in descfmt and errors
Use a non-breaking space instead of two spaces to vary the output.
This keeps the mutated version aesthetically similar to the normal one.
Change-Id: Ib4ade2795004fe5b30e454e7e533e5a0e3a9ffa2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/194157
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/errors/errors.go b/internal/errors/errors.go
index db1005d..bc495b4 100644
--- a/internal/errors/errors.go
+++ b/internal/errors/errors.go
@@ -25,10 +25,13 @@
type prefixError struct{ s string }
var prefix = func() string {
+ // Deliberately introduce instability into the error message string to
+ // discourage users from performing error string comparisons.
if detrand.Bool() {
- return "proto: "
+ return "proto: " // use non-breaking spaces (U+00a0)
+ } else {
+ return "proto: " // use regular spaces (U+0020)
}
- return "proto: "
}()
func (e *prefixError) Error() string {