cockroach: github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror Index | Files

package pgerror

import "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"

Index

Package Files

errors.go errors.pb.go flatten.go internal_errors.go pgcode.go with_candidate_code.go wrap.go

Constants

const InternalErrorPrefix = "internal error"

InternalErrorPrefix is prepended on internal errors.

const TxnRetryMsgPrefix = "restart transaction"

TxnRetryMsgPrefix is the prefix inserted in an error message when flattened

Variables

var (
    ErrInvalidLengthErrors = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowErrors   = fmt.Errorf("proto: integer overflow")
)

func ComputeDefaultCode Uses

func ComputeDefaultCode(err error) string

ComputeDefaultCode looks at the current error object (not its causes) and returns: - the existing code for Error instances - SerializationFailure for roachpb retry errors that can be reported to clients - StatementCompletionUnknown for ambiguous commit errors - InternalError for assertion failures - FeatureNotSupportedError for unimplemented errors.

func DangerousStatementf Uses

func DangerousStatementf(format string, args ...interface{}) error

DangerousStatementf creates a new error for "rejected dangerous statements".

func FullError Uses

func FullError(err error) string

FullError can be used when the hint and/or detail are to be tested.

func GetPGCode Uses

func GetPGCode(err error) string

GetPGCode retrieves the error code for an error.

func GetPGCodeInternal Uses

func GetPGCodeInternal(err error, computeDefaultCode func(err error) (code string)) (code string)

GetPGCodeInternal retrieves a code for the error. It operates by combining the inner (cause) code and the code at the current level, at each level of cause.

- at each level:

- if there is a candidate code at that level, that is used;
- otherwise, it calls computeDefaultCode().
  if the function returns an empty string,
  UncategorizedError is used.
  An example implementation for computeDefaultCode is provided below.

- after that, it combines the code computed already for the cause

(inner) and the new code just computed at the current level (outer)
as follows:

- if the outer code is uncategorized, the inner code is kept no
  matter what.
- if the outer code has the special XX prefix, that is kept.
  (The "XX" prefix signals importance in the pg code hierarchy.)
- if the inner code is not uncategorized, it is retained.
- otherwise the outer code is retained.

func HasCandidateCode Uses

func HasCandidateCode(err error) bool

HasCandidateCode returns tue iff the error or one of its causes has a candidate pg error code.

func IsCandidateCode Uses

func IsCandidateCode(err error) bool

IsCandidateCode returns true iff the error (not its causes) has a candidate pg error code.

func IsSQLRetryableError Uses

func IsSQLRetryableError(err error) bool

IsSQLRetryableError returns true if err is retryable. This is true for errors that show a connection issue or an issue with the node itself. This can occur when a node is restarting or is unstable in some other way. Note that retryable errors may occur event in cases where the SQL execution ran to completion.

TODO(bdarnell): Why are RPC errors in this list? These should generally be retried on the server side or transformed into ambiguous result errors ("connection reset/refused" are needed for the pgwire connection, but anything RPC-related should be handled within the cluster). TODO(knz): This should really use the errors library. Investigate how to get rid of the error message comparison.

func New Uses

func New(code string, msg string) error

New creates an error with a code.

func NewInternalTrackingError Uses

func NewInternalTrackingError(issue int, detail string) error

NewInternalTrackingError instantiates an error meant for use with telemetry.ReportError directly.

Do not use this! Convert uses to AssertionFailedf or similar above.

func NewWithDepthf Uses

func NewWithDepthf(depth int, code string, format string, args ...interface{}) error

NewWithDepthf creates an error with a pg code and extracts the context information at the specified depth level.

func Newf Uses

func Newf(code string, format string, args ...interface{}) error

Newf creates an Error with a format string.

func WithCandidateCode Uses

func WithCandidateCode(err error, code string) error

WithCandidateCode decorates the error with a candidate postgres error code. It is called "candidate" because the code is only used by GetPGCode() below conditionally. The code is considered PII-free and is thus reportable.

func Wrap Uses

func Wrap(err error, code, msg string) error

Wrap wraps an error and adds a pg error code. Only the code is added if the message is empty.

func WrapWithDepthf Uses

func WrapWithDepthf(depth int, err error, code, format string, args ...interface{}) error

WrapWithDepthf wraps an error. It also annotates the provided pg code as new candidate code, to be used if the underlying error does not have one already.

func Wrapf Uses

func Wrapf(err error, code, format string, args ...interface{}) error

Wrapf wraps an error and adds a pg error code. See the doc on WrapWithDepthf for details.

func WrongNumberOfPreparedStatements Uses

func WrongNumberOfPreparedStatements(n int) error

WrongNumberOfPreparedStatements creates new an Error for trying to prepare a query string containing more than one statement.

type ClientVisibleAmbiguousError Uses

type ClientVisibleAmbiguousError interface {
    ClientVisibleAmbiguousError()
}

ClientVisibleAmbiguousError mirrors roachpb.ClientVisibleAmbiguousError but is defined here to avoid an import cycle.

type ClientVisibleRetryError Uses

type ClientVisibleRetryError interface {
    ClientVisibleRetryError()
}

ClientVisibleRetryError mirrors roachpb.ClientVisibleRetryError but is defined here to avoid an import cycle.

type Error Uses

type Error struct {
    // standard pg error fields. This can be passed
    // over the pg wire protocol.
    Code    string        `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
    Message string        `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
    Detail  string        `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"`
    Hint    string        `protobuf:"bytes,4,opt,name=hint,proto3" json:"hint,omitempty"`
    Source  *Error_Source `protobuf:"bytes,5,opt,name=source,proto3" json:"source,omitempty"`
    // a telemetry key, used as telemetry counter name.
    // Typically of the form [<prefix>.]#issuenum[.details]
    //
    // Note: this field is obsolete. It is preserved for compatibility
    // with nodes running 19.1:
    //
    // - when an error with this field populated is received on a
    //   post-19.1 node, the field is replaced by uses of
    //   errors.WithTelemetryKey. This data is then subsequently used for
    //   troubleshooting reports and telemetry.
    // - Conversely, errors sent towards a 19.1 node will get this field
    //   populated with the first key found in errors.GetTelemetryKeys().
    //
    // TODO(knz): Remove in 19.3.
    TelemetryKey string `protobuf:"bytes,6,opt,name=telemetry_key,json=telemetryKey,proto3" json:"telemetry_key,omitempty"`
    // complement to the detail field that can be reported
    // in sentry reports. This is scrubbed of PII.
    //
    // Note: this field is obsolete. It is preserved for compatibility
    // with nodes running 19.1:
    //
    // - when an error with this field populated is received on a
    //   post-19.1 node, the field is replaced by uses of
    //   errors.WithSafeDetail. This data is then subsequently used for
    //   troubleshooting reports.
    // - Conversely, errors sent towards a 19.1 node will get this field
    //   populated with the data from errors.GetSafeDetails().
    //
    // TODO(knz): Remove in 19.3.
    SafeDetail []*Error_SafeDetail `protobuf:"bytes,7,rep,name=safe_detail,json=safeDetail,proto3" json:"safe_detail,omitempty"`
}

Error contains all Postgres wire protocol error fields. See https://www.postgresql.org/docs/current/static/protocol-error-fields.html for a list of all Postgres error fields, most of which are optional and can be used to provide auxiliary error information.

func Flatten Uses

func Flatten(err error) *Error

Flatten turns any error into a pgerror with fields populated. As the name implies, the details from the chain of causes is projected into a single struct. This is useful in at least two places:

- to generate Error objects suitable for 19.1 nodes, which

only recognize this type of payload.

- to generate an error packet on pgwire.

Additionally, this can be used in the remainder of the code base when an Error object is expected, until that code is updated to use the errors library directly.

Flatten() returns a nil ptr if err was nil to start with.

func (*Error) Descriptor Uses

func (*Error) Descriptor() ([]byte, []int)

func (*Error) Error Uses

func (pg *Error) Error() string

Error implements the error interface.

func (*Error) ErrorDetail Uses

func (pg *Error) ErrorDetail() string

ErrorDetail implements the hintdetail.ErrorDetailer interface.

func (*Error) ErrorHint Uses

func (pg *Error) ErrorHint() string

ErrorHint implements the hintdetail.ErrorHinter interface.

func (*Error) Format Uses

func (pg *Error) Format(s fmt.State, verb rune)

Format implements the fmt.Formatter interface.

%v/%s prints the error as usual. %#v adds the pg error code at the beginning. %+v prints all the details, including the embedded stack traces.

func (*Error) Marshal Uses

func (m *Error) Marshal() (dAtA []byte, err error)

func (*Error) MarshalTo Uses

func (m *Error) MarshalTo(dAtA []byte) (int, error)

func (*Error) ProtoMessage Uses

func (*Error) ProtoMessage()

func (*Error) Reset Uses

func (m *Error) Reset()

func (*Error) SafeDetails Uses

func (pg *Error) SafeDetails() []string

SafeDetails implements the errbase.SafeDetailer interface. TODO(knz): this is provided for compatibility with 19.1 nodes. Remove in 19.3, together with the "SafeDetail" proto field.

func (*Error) Size Uses

func (m *Error) Size() (n int)

func (*Error) String Uses

func (m *Error) String() string

func (*Error) Unmarshal Uses

func (m *Error) Unmarshal(dAtA []byte) error

func (*Error) XXX_DiscardUnknown Uses

func (m *Error) XXX_DiscardUnknown()

func (*Error) XXX_Marshal Uses

func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Error) XXX_Merge Uses

func (dst *Error) XXX_Merge(src proto.Message)

func (*Error) XXX_Size Uses

func (m *Error) XXX_Size() int

func (*Error) XXX_Unmarshal Uses

func (m *Error) XXX_Unmarshal(b []byte) error

type Error_SafeDetail Uses

type Error_SafeDetail struct {
    SafeMessage       string `protobuf:"bytes,1,opt,name=safe_message,json=safeMessage,proto3" json:"safe_message,omitempty"`
    EncodedStackTrace string `protobuf:"bytes,2,opt,name=encoded_stack_trace,json=encodedStackTrace,proto3" json:"encoded_stack_trace,omitempty"`
}

func (*Error_SafeDetail) Descriptor Uses

func (*Error_SafeDetail) Descriptor() ([]byte, []int)

func (*Error_SafeDetail) Marshal Uses

func (m *Error_SafeDetail) Marshal() (dAtA []byte, err error)

func (*Error_SafeDetail) MarshalTo Uses

func (m *Error_SafeDetail) MarshalTo(dAtA []byte) (int, error)

func (*Error_SafeDetail) ProtoMessage Uses

func (*Error_SafeDetail) ProtoMessage()

func (*Error_SafeDetail) Reset Uses

func (m *Error_SafeDetail) Reset()

func (*Error_SafeDetail) Size Uses

func (m *Error_SafeDetail) Size() (n int)

func (*Error_SafeDetail) String Uses

func (m *Error_SafeDetail) String() string

func (*Error_SafeDetail) Unmarshal Uses

func (m *Error_SafeDetail) Unmarshal(dAtA []byte) error

func (*Error_SafeDetail) XXX_DiscardUnknown Uses

func (m *Error_SafeDetail) XXX_DiscardUnknown()

func (*Error_SafeDetail) XXX_Marshal Uses

func (m *Error_SafeDetail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Error_SafeDetail) XXX_Merge Uses

func (dst *Error_SafeDetail) XXX_Merge(src proto.Message)

func (*Error_SafeDetail) XXX_Size Uses

func (m *Error_SafeDetail) XXX_Size() int

func (*Error_SafeDetail) XXX_Unmarshal Uses

func (m *Error_SafeDetail) XXX_Unmarshal(b []byte) error

type Error_Source Uses

type Error_Source struct {
    File     string `protobuf:"bytes,1,opt,name=file,proto3" json:"file,omitempty"`
    Line     int32  `protobuf:"varint,2,opt,name=line,proto3" json:"line,omitempty"`
    Function string `protobuf:"bytes,3,opt,name=function,proto3" json:"function,omitempty"`
}

func (*Error_Source) Descriptor Uses

func (*Error_Source) Descriptor() ([]byte, []int)

func (*Error_Source) Marshal Uses

func (m *Error_Source) Marshal() (dAtA []byte, err error)

func (*Error_Source) MarshalTo Uses

func (m *Error_Source) MarshalTo(dAtA []byte) (int, error)

func (*Error_Source) ProtoMessage Uses

func (*Error_Source) ProtoMessage()

func (*Error_Source) Reset Uses

func (m *Error_Source) Reset()

func (*Error_Source) Size Uses

func (m *Error_Source) Size() (n int)

func (*Error_Source) String Uses

func (m *Error_Source) String() string

func (*Error_Source) Unmarshal Uses

func (m *Error_Source) Unmarshal(dAtA []byte) error

func (*Error_Source) XXX_DiscardUnknown Uses

func (m *Error_Source) XXX_DiscardUnknown()

func (*Error_Source) XXX_Marshal Uses

func (m *Error_Source) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Error_Source) XXX_Merge Uses

func (dst *Error_Source) XXX_Merge(src proto.Message)

func (*Error_Source) XXX_Size Uses

func (m *Error_Source) XXX_Size() int

func (*Error_Source) XXX_Unmarshal Uses

func (m *Error_Source) XXX_Unmarshal(b []byte) error

Package pgerror imports 14 packages (graph) and is imported by 75 packages. Updated 2019-07-10. Refresh now. Tools for package owners.