all: remove non-fatal UTF-8 validation errors (and non-fatal in general)

Immediately abort (un)marshal operations when encountering invalid UTF-8
data in proto3 strings. No other proto implementation supports non-UTF-8
data in proto3 strings (and many reject it in proto2 strings as well).
Producing invalid output is an interoperability threat (other
implementations won't be able to read it).

The case where existing string data is found to contain non-UTF8 data is
better handled by changing the field to the `bytes` type, which (aside
from UTF-8 validation) is wire-compatible with `string`.

Remove the errors.NonFatal type, since there are no remaining cases
where it is needed. "Non-fatal" errors which produce results and a
non-nil error are problematic because they compose poorly; the better
approach is to take an option like AllowPartial indicating which
conditions to check for.

Change-Id: I9d189ec6ffda7b5d96d094aa1b290af2e3f23736
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/183098
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/encoding/text/decode.go b/internal/encoding/text/decode.go
index 0babddf..2b32ed9 100644
--- a/internal/encoding/text/decode.go
+++ b/internal/encoding/text/decode.go
@@ -26,7 +26,7 @@
 	p := decoder{in: b}
 	p.consume(0) // trim leading spaces or comments
 	v, err := p.unmarshalMessage(false)
-	if !p.nerr.Merge(err) {
+	if err != nil {
 		if e, ok := err.(syntaxError); ok {
 			b = b[:len(b)-len(p.in)] // consumed input
 			line := bytes.Count(b, []byte("\n")) + 1
@@ -41,12 +41,11 @@
 	if len(p.in) > 0 {
 		return Value{}, errors.New("%d bytes of unconsumed input", len(p.in))
 	}
-	return v, p.nerr.E
+	return v, nil
 }
 
 type decoder struct {
-	nerr errors.NonFatal
-	in   []byte
+	in []byte
 }
 
 func (p *decoder) unmarshalList() (Value, error) {
@@ -58,7 +57,7 @@
 	if len(p.in) > 0 && p.in[0] != ']' {
 		for len(p.in) > 0 {
 			v, err := p.unmarshalValue()
-			if !p.nerr.Merge(err) {
+			if err != nil {
 				return Value{}, err
 			}
 			elems = append(elems, v)
@@ -91,14 +90,14 @@
 			break
 		}
 		k, err := p.unmarshalKey()
-		if !p.nerr.Merge(err) {
+		if err != nil {
 			return Value{}, err
 		}
 		if !p.tryConsumeChar(':') && len(p.in) > 0 && p.in[0] != '{' && p.in[0] != '<' {
 			return Value{}, newSyntaxError("expected ':' after message key")
 		}
 		v, err := p.unmarshalValue()
-		if !p.nerr.Merge(err) {
+		if err != nil {
 			return Value{}, err
 		}
 		if p.tryConsumeChar(';') || p.tryConsumeChar(',') {
@@ -132,7 +131,7 @@
 			// This is specific to Go and contrary to the C++ implementation,
 			// which does not support strings for the Any type URL.
 			v, err = p.unmarshalString()
-			if !p.nerr.Merge(err) {
+			if err != nil {
 				return Value{}, err
 			}
 		} else if n := matchWithDelim(urlRegexp, p.in); n > 0 {