Documentation ¶
Overview ¶
Package trace implements utility functions for capturing debugging information about file and line in error reports and logs.
Index ¶
- func ConvertSystemError(err error) error
- func DebugReport(err error) string
- func ErrorToCode(err error) int
- func Errorf(format string, args ...interface{}) (err error)
- func Fatalf(format string, args ...interface{}) error
- func GetFields(err error) map[string]interface{}
- func IsAccessDenied(e error) bool
- func IsAggregate(err error) bool
- func IsAlreadyExists(e error) bool
- func IsBadParameter(e error) bool
- func IsCompareFailed(e error) bool
- func IsConnectionProblem(e error) bool
- func IsDebug() bool
- func IsEOF(e error) bool
- func IsLimitExceeded(e error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(e error) bool
- func IsOAuth2(e error) bool
- func IsRetryError(e error) bool
- func IsTrustError(e error) bool
- func NewAggregate(errs ...error) error
- func NewAggregateFromChannel(errCh chan error, ctx context.Context) error
- func ReadError(statusCode int, respBytes []byte) error
- func SetDebug(enabled bool)
- func Unwrap(err error) error
- func UserMessage(err error) string
- func UserMessageWithFields(err error) string
- func WriteError(w http.ResponseWriter, err error)
- type AccessDeniedError
- type Aggregate
- type AlreadyExistsError
- type BadParameterError
- type CompareFailedError
- type ConnectionProblemError
- type DebugReporter
- type Error
- func AccessDenied(message string, args ...interface{}) Error
- func AlreadyExists(message string, args ...interface{}) Error
- func BadParameter(message string, args ...interface{}) Error
- func CompareFailed(message string, args ...interface{}) Error
- func ConnectionProblem(err error, message string, args ...interface{}) Error
- func LimitExceeded(message string, args ...interface{}) Error
- func NotFound(message string, args ...interface{}) Error
- func NotImplemented(message string, args ...interface{}) Error
- func OAuth2(code, message string, query url.Values) Error
- func Retry(err error, message string, args ...interface{}) Error
- func Trust(err error, message string, args ...interface{}) Error
- func Wrap(err error, args ...interface{}) Error
- func WrapWithMessage(err error, message interface{}, args ...interface{}) Error
- type ErrorWrapper
- type Fields
- type LimitExceededError
- type NotFoundError
- type NotImplementedError
- type OAuth2Error
- type RawTrace
- type RetryError
- type Trace
- type TraceErr
- func (e *TraceErr) Clone() *TraceErr
- func (e *TraceErr) DebugReport() string
- func (e *TraceErr) Error() string
- func (e *TraceErr) GetFields() map[string]interface{}
- func (e *TraceErr) GoString() string
- func (e *TraceErr) MarshalJSON() ([]byte, error)
- func (e *TraceErr) OrigError() error
- func (e *TraceErr) Unwrap() error
- func (e *TraceErr) UserMessage() string
- type Traces
- type TrustError
- type UserMessager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSystemError ¶
ConvertSystemError converts system error to appropriate trace error if it is possible, otherwise, returns original error
func DebugReport ¶
DebugReport returns debug report with all known information about the error including stack trace if it was captured
func ErrorToCode ¶ added in v1.1.2
ErrorToCode returns an appropriate HTTP status code based on the provided error type
func Errorf ¶
Errorf is similar to fmt.Errorf except that it captures more information about the origin of error, such as callee, line number and function that simplifies debugging
func GetFields ¶ added in v1.1.7
GetFields returns any fields that have been added to the error message
func IsAccessDenied ¶
IsAccessDenied returns true if `e` contains an AccessDeniedError in its chain.
func IsAggregate ¶
IsAggregate returns true if `err` contains an Aggregate error in its chain.
func IsAlreadyExists ¶
IsAlreadyExists returns true if `e` contains an AlreadyExistsError in its chain.
func IsBadParameter ¶
IsBadParameter returns true if `e` contains a BadParameterError in its chain.
func IsCompareFailed ¶
IsCompareFailed returns true if `e` contains a CompareFailedError in its chain.
func IsConnectionProblem ¶
IsConnectionProblem returns true if `e` contains a ConnectionProblemError in its chain.
func IsLimitExceeded ¶
IsLimitExceeded returns true if `e` contains a LimitExceededError in its chain.
func IsNotFound ¶
IsNotFound returns true if `e` contains a NotFoundError in its chain.
func IsNotImplemented ¶ added in v1.1.5
IsNotImplemented returns true if `e` contains a NotImplementedError in its chain.
func IsOAuth2 ¶
IsOAuth2 returns true if `e` contains an OAuth2Error in its chain.
func IsRetryError ¶
IsRetryError returns true if `e` contains a RetryError in its chain.
func IsTrustError ¶
IsTrustError returns true if `e` contains a TrustError in its chain.
func NewAggregate ¶
NewAggregate creates a new aggregate instance from the specified list of errors
func NewAggregateFromChannel ¶
NewAggregateFromChannel creates a new aggregate instance from the provided errors channel.
A context.Context can be passed in so the caller has the ability to cancel the operation. If this is not desired, simply pass context.Background().
func ReadError ¶
ReadError converts http error to internal error type based on HTTP response code and HTTP body contents if status code does not indicate error, it will return nil
func SetDebug ¶
func SetDebug(enabled bool)
SetDebug turns on/off debugging mode, that causes Fatalf to panic
func Unwrap ¶
Unwrap returns the original error the given error wraps. It is equivalent to removing all trace layers until the original error is exposed.
Unwrap works mainly on trace errors, so it won't unwrap errors wrapped via Go's `%w`.
Prefer using higher-level comparison methods, such as the various "IsError" functions in this package or errors.Is and errors.As. If you want a general error-unwrapping mechanism, consider using errors.Unwrap instead.
func UserMessage ¶
UserMessage returns user-friendly part of the error
func UserMessageWithFields ¶ added in v1.1.7
UserMessageWithFields returns user-friendly error with key-pairs as part of the message
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError sets up HTTP error response and writes it to writer w
Types ¶
type AccessDeniedError ¶
type AccessDeniedError struct {
Message string `json:"message"`
}
AccessDeniedError indicates denied access
func (*AccessDeniedError) Error ¶
func (e *AccessDeniedError) Error() string
Error is debug - friendly error message
func (*AccessDeniedError) Is ¶ added in v1.1.16
func (e *AccessDeniedError) Is(target error) bool
Is provides an equivalency check for AccessDeniedError to be used with errors.Is
func (*AccessDeniedError) IsAccessDeniedError ¶
func (e *AccessDeniedError) IsAccessDeniedError() bool
IsAccessDeniedError indicates that this error is of AccessDeniedError type
func (*AccessDeniedError) OrigError ¶
func (e *AccessDeniedError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type Aggregate ¶
type Aggregate interface { error // Errors obtains the list of errors this aggregate combines Errors() []error }
Aggregate interface combines several errors into one error
type AlreadyExistsError ¶
type AlreadyExistsError struct {
Message string `json:"message"`
}
AlreadyExistsError indicates that there's a duplicate object that already exists in the storage/system
func (*AlreadyExistsError) Error ¶
func (e *AlreadyExistsError) Error() string
Error returns log friendly description of an error
func (*AlreadyExistsError) Is ¶ added in v1.1.16
func (e *AlreadyExistsError) Is(target error) bool
Is provides an equivalency check for AlreadyExistsError to be used with errors.Is
func (AlreadyExistsError) IsAlreadyExistsError ¶
func (AlreadyExistsError) IsAlreadyExistsError() bool
IsAlreadyExistsError indicates that this error of the AlreadyExistsError type
func (*AlreadyExistsError) OrigError ¶
func (e *AlreadyExistsError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type BadParameterError ¶
type BadParameterError struct {
Message string `json:"message"`
}
BadParameterError indicates that something is wrong with passed parameter to API method
func (*BadParameterError) Error ¶
func (b *BadParameterError) Error() string
Error returns log friendly description of an error
func (*BadParameterError) Is ¶ added in v1.1.16
func (b *BadParameterError) Is(target error) bool
Is provides an equivalency check for BadParameterError to be used with errors.Is
func (*BadParameterError) IsBadParameterError ¶
func (b *BadParameterError) IsBadParameterError() bool
IsBadParameterError indicates that this error is of BadParameterError type
func (*BadParameterError) OrigError ¶
func (b *BadParameterError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type CompareFailedError ¶
type CompareFailedError struct { // Message is user-friendly error message Message string `json:"message"` }
CompareFailedError indicates a failed comparison (e.g. bad password or hash)
func (*CompareFailedError) Error ¶
func (e *CompareFailedError) Error() string
Error is debug - friendly message
func (*CompareFailedError) Is ¶ added in v1.1.16
func (e *CompareFailedError) Is(target error) bool
Is provides an equivalency check for CompareFailedError to be used with errors.Is
func (*CompareFailedError) IsCompareFailedError ¶
func (e *CompareFailedError) IsCompareFailedError() bool
IsCompareFailedError indicates that this is CompareFailedError
func (*CompareFailedError) OrigError ¶
func (e *CompareFailedError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type ConnectionProblemError ¶
ConnectionProblemError indicates a network related problem
func (*ConnectionProblemError) Error ¶
func (c *ConnectionProblemError) Error() string
Error is debug - friendly error message
func (*ConnectionProblemError) Is ¶ added in v1.1.16
func (c *ConnectionProblemError) Is(target error) bool
Is provides an equivalency check for ConnectionProblemError to be used with errors.Is
func (*ConnectionProblemError) IsConnectionProblemError ¶
func (c *ConnectionProblemError) IsConnectionProblemError() bool
IsConnectionProblemError indicates that this error is of ConnectionProblemError type
func (*ConnectionProblemError) OrigError ¶
func (c *ConnectionProblemError) OrigError() error
OrigError returns original error
func (*ConnectionProblemError) Unwrap ¶ added in v1.1.13
func (c *ConnectionProblemError) Unwrap() error
Unwrap returns the wrapped error if any
type DebugReporter ¶ added in v1.1.11
type DebugReporter interface { // DebugReport formats an error for display DebugReport() string }
DebugReporter formats an error for display
type Error ¶
type Error interface { error ErrorWrapper DebugReporter UserMessager // GetFields returns any fields that have been added to the error GetFields() map[string]interface{} // Clone returns a copy of the current Error. Clone() *TraceErr }
Error is an interface that helps to adapt usage of trace in the code When applications define new error types, they can implement the interface
Error handlers can use Unwrap() to retrieve error from the wrapper, or errors.Is()/As() to compare it to another value.
func AccessDenied ¶
AccessDenied returns new instance of AccessDeniedError
func AlreadyExists ¶
AlreadyExists returns a new instance of AlreadyExists error
func BadParameter ¶
BadParameter returns a new instance of BadParameterError
func CompareFailed ¶
CompareFailed returns new instance of CompareFailedError
func ConnectionProblem ¶
ConnectionProblem returns new instance of ConnectionProblemError
func LimitExceeded ¶
LimitExceeded returns whether new instance of LimitExceededError
func NotImplemented ¶ added in v1.1.5
NotImplemented returns a new instance of NotImplementedError
func Wrap ¶
Wrap takes the original error and wraps it into the Trace struct memorizing the context of the error.
func WrapWithMessage ¶
WrapWithMessage wraps the original error into Error and adds user message if any
type ErrorWrapper ¶ added in v1.1.11
type ErrorWrapper interface { // OrigError returns the wrapped error OrigError() error }
ErrorWrapper wraps another error
type Fields ¶ added in v1.1.8
type Fields map[string]interface{}
Fields maps arbitrary keys to values inside an error
type LimitExceededError ¶
type LimitExceededError struct {
Message string `json:"message"`
}
LimitExceededError indicates rate limit or connection limit problem
func (*LimitExceededError) Error ¶
func (e *LimitExceededError) Error() string
Error is debug - friendly error message
func (*LimitExceededError) Is ¶ added in v1.1.16
func (e *LimitExceededError) Is(target error) bool
Is provides an equivalency check for LimitExceededError to be used with errors.Is
func (*LimitExceededError) IsLimitExceededError ¶
func (e *LimitExceededError) IsLimitExceededError() bool
IsLimitExceededError indicates that this error is of ConnectionProblem
func (*LimitExceededError) OrigError ¶
func (e *LimitExceededError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type NotFoundError ¶
type NotFoundError struct {
Message string `json:"message"`
}
NotFoundError indicates that object has not been found
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
Error returns log friendly description of an error
func (*NotFoundError) Is ¶ added in v1.1.16
func (e *NotFoundError) Is(target error) bool
Is provides an equivalency check for NotFoundError to be used with errors.Is
func (*NotFoundError) IsNotFoundError ¶
func (e *NotFoundError) IsNotFoundError() bool
IsNotFoundError returns true to indicate that is NotFoundError
func (*NotFoundError) OrigError ¶
func (e *NotFoundError) OrigError() error
OrigError returns original error (in this case this is the error itself)
type NotImplementedError ¶ added in v1.1.5
type NotImplementedError struct {
Message string `json:"message"`
}
NotImplementedError defines an error condition to describe the result of a call to an unimplemented API
func (*NotImplementedError) Error ¶ added in v1.1.5
func (e *NotImplementedError) Error() string
Error returns log friendly description of an error
func (*NotImplementedError) Is ¶ added in v1.1.16
func (e *NotImplementedError) Is(target error) bool
Is provides an equivalency check for NotImplementedError to be used with errors.Is
func (*NotImplementedError) IsNotImplementedError ¶ added in v1.1.5
func (e *NotImplementedError) IsNotImplementedError() bool
IsNotImplementedError indicates that this error is of NotImplementedError type
func (*NotImplementedError) OrigError ¶ added in v1.1.5
func (e *NotImplementedError) OrigError() error
OrigError returns original error
type OAuth2Error ¶
type OAuth2Error struct { Code string `json:"code"` Message string `json:"message"` Query url.Values `json:"query"` }
OAuth2Error defined an error used in OpenID Connect Flow (OIDC)
func (*OAuth2Error) Error ¶
func (o *OAuth2Error) Error() string
Error returns log friendly description of an error
func (*OAuth2Error) Is ¶ added in v1.1.16
func (o *OAuth2Error) Is(target error) bool
Is provides an equivalency check for OAuth2Error to be used with errors.Is
func (*OAuth2Error) IsOAuth2Error ¶
func (o *OAuth2Error) IsOAuth2Error() bool
IsOAuth2Error returns whether this error of OAuth2Error type
type RawTrace ¶
type RawTrace struct { // Err specifies the original error Err json.RawMessage `json:"error,omitempty"` // Traces lists the stack traces at the moment the error was recorded Traces `json:"traces,omitempty"` // Message specifies the optional user-facing message Message string `json:"message,omitempty"` // Messages is a list of user messages added to this error. Messages []string `json:"messages,omitempty"` // Fields is a list of key-value-pairs that can be wrapped with the error to give additional context Fields map[string]interface{} `json:"fields,omitempty"` }
RawTrace describes the error trace on the wire
type RetryError ¶
RetryError indicates a transient error type
func (*RetryError) Error ¶
func (c *RetryError) Error() string
Error is debug-friendly error message
func (*RetryError) Is ¶ added in v1.1.16
func (c *RetryError) Is(target error) bool
Is provides an equivalency check for RetryError to be used with errors.Is
func (*RetryError) IsRetryError ¶
func (c *RetryError) IsRetryError() bool
IsRetryError indicates that this error is of RetryError type
func (*RetryError) OrigError ¶
func (c *RetryError) OrigError() error
OrigError returns original error (in this case this is the error itself)
func (*RetryError) Unwrap ¶ added in v1.1.13
func (c *RetryError) Unwrap() error
Unwrap returns the wrapped error if any
type TraceErr ¶
type TraceErr struct { // Err is the underlying error that TraceErr wraps Err error `json:"error"` // Traces is a slice of stack trace entries for the error Traces `json:"-"` // Message is an optional message that can be wrapped with the original error. // // This field is obsolete, replaced by messages list below. Message string `json:"message,omitempty"` // Messages is a list of user messages added to this error. Messages []string `json:"messages,omitempty"` // Fields is a list of key-value-pairs that can be wrapped with the error to give additional context Fields map[string]interface{} `json:"fields,omitempty"` }
TraceErr contains error message and some additional information about the error origin
func WithFields ¶ added in v1.2.0
WithFields adds a map of additional fields to the error
func WithUserMessage ¶ added in v1.2.0
WithUserMessage adds formatted user-facing message to the error, depends on the implementation, usually works as fmt.Sprintf(formatArg, rest...) but implementations can choose another way, e.g. treat arguments as structured args.
func (*TraceErr) DebugReport ¶
DebugReport returns developer-friendly error report
func (*TraceErr) GoString ¶ added in v1.1.6
GoString formats this trace object for use with the "%#v" format string
func (*TraceErr) MarshalJSON ¶ added in v1.1.11
MarshalJSON marshals this error as JSON-encoded payload
func (*TraceErr) Unwrap ¶ added in v1.1.12
Unwrap returns the error this TraceErr wraps. The returned error may also wrap another one, Unwrap doesn't recursively get the inner-most error like OrigError does.
func (*TraceErr) UserMessage ¶
UserMessage returns user-friendly error message
type TrustError ¶
type TrustError struct { // Err is original error Err error `json:"-"` Message string `json:"message"` }
TrustError indicates trust-related validation error (e.g. untrusted cert)
func (*TrustError) Error ¶
func (t *TrustError) Error() string
Error returns log-friendly error description
func (*TrustError) Is ¶ added in v1.1.16
func (t *TrustError) Is(target error) bool
Is provides an equivalency check for TrustError to be used with errors.Is
func (*TrustError) IsTrustError ¶
func (*TrustError) IsTrustError() bool
IsTrustError indicates that this error is of TrustError type
func (*TrustError) OrigError ¶
func (t *TrustError) OrigError() error
OrigError returns original error (in this case this is the error itself)
func (*TrustError) Unwrap ¶ added in v1.1.13
func (t *TrustError) Unwrap() error
Unwrap returns the wrapped error if any
type UserMessager ¶ added in v1.1.13
type UserMessager interface { // UserMessage returns the user message associated with the error if any UserMessage() string }
UserMessager returns a user message associated with the error