// 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, ...any) error {return &prefixError{s: format(, ...)}}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.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, ...any) error {return &wrapError{s: format(, ...),err: , }}type wrapError struct { s string err error}func ( *wrapError) () string {returnformat("%v%v: %v", prefix, .s, .err)}func ( *wrapError) () error {return .err}func ( *wrapError) ( error) bool {return == Error}func format( string, ...any) 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", )}typeSizeMismatchErrorstruct { Calculated, Measured int}func ( *SizeMismatchError) () string {returnfmt.Sprintf("size mismatch (see https://github.com/golang/protobuf/issues/1609): calculated=%d, measured=%d", .Calculated, .Measured)}func (, int) error {return &SizeMismatchError{Calculated: ,Measured: , }}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.