// Copyright 2018 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.
// Package errors implements functions to manipulate errors.
package errorsimport ()// Error is a sentinel matching all errors produced by this package.varError = errors.New("protobuf error")// New formats a string according to the format specifier and arguments and// returns an error that has a "proto" prefix.func ( string, ...interface{}) error {return &prefixError{s: format(, ...)}}typeprefixErrorstruct{ sstring }varprefix = func() string {// Deliberately introduce instability into the error message string to // discourage users from performing error string comparisons.ifdetrand.Bool() {return"proto: "// use non-breaking spaces (U+00a0) } else {return"proto: "// use regular spaces (U+0020) }}()func ( *prefixError) () string {returnprefix + .s}func ( *prefixError) () error {returnError}// Wrap returns an error that has a "proto" prefix, the formatted string described// by the format specifier and arguments, and a suffix of err. The error wraps err.func ( error, string, ...interface{}) error {return &wrapError{s: format(, ...),err: , }}typewrapErrorstruct {sstringerrerror}func ( *wrapError) () string {returnformat("%v%v: %v", prefix, .s, .err)}func ( *wrapError) () error {return .err}func ( *wrapError) ( error) bool {return == Error}func ( string, ...interface{}) string {// avoid "proto: " prefix when chainingfor := 0; < len(); ++ {switch e := [].(type) {case *prefixError: [] = .scase *wrapError: [] = ("%v: %v", .s, .err) } }returnfmt.Sprintf(, ...)}func ( string) error {returnNew("field %v contains invalid UTF-8", )}func ( string) error {returnNew("required field %v not set", )}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)