Documentation ¶
Overview ¶
Package xerror provides a way to wrap errors with additional context and to add variables to the error that can be logged at a later time. It also provides a way to categorize errors into different kinds.
Index ¶
- Variables
- func DomainType(domain, reason string) string
- func ErrorGuide() errorGuide
- func Init(domain string)
- func Wrap(err error, msg string) error
- type BadRequestViolation
- type DebugInfo
- type Error
- func From(err error) *Error
- func NewAborted(opts ErrorInfoOptions) *Error
- func NewAlreadyExists(info ResourceInfo) *Error
- func NewAlreadyExistsBatch(infos []ResourceInfo) *Error
- func NewCancelled() *Error
- func NewDeadlineExceeded() *Error
- func NewInternal(err error) *Error
- func NewInvalidArgument(field, description string) *Error
- func NewInvalidArgumentBatch(violations []BadRequestViolation) *Error
- func NewNotFound(info ResourceInfo) *Error
- func NewNotFoundBatch(infos []ResourceInfo) *Error
- func NewNotImplemented() *Error
- func NewOutOfRange(field, description string) *Error
- func NewOutOfRangeBatch(violations []BadRequestViolation) *Error
- func NewPermissionDenied(opts ErrorInfoOptions) *Error
- func NewPreconditionFailure(subject, typ, description string) *Error
- func NewPreconditionFailureBatch(violations []PreconditionViolation) *Error
- func NewQuotaFailure(subject, description string) *Error
- func NewQuotaFailureBatch(violations []QuotaViolation) *Error
- func NewRequestDataLoss(opts ErrorInfoOptions) *Error
- func NewResourceExhausted(opts ErrorInfoOptions) *Error
- func NewServerDataLoss(err error) *Error
- func NewUnauthenticated(opts ErrorInfoOptions) *Error
- func NewUnavailable(err error) *Error
- func NewUnknown(err error) *Error
- func (xerr *Error) AddBadRequestViolations(violations []BadRequestViolation) *Error
- func (xerr *Error) AddPreconditionViolations(violations []PreconditionViolation) *Error
- func (xerr *Error) AddQuotaViolations(violations []QuotaViolation) *Error
- func (xerr *Error) AddResourceInfos(infos []ResourceInfo) *Error
- func (xerr *Error) AddVar(name string, value any) *Error
- func (xerr *Error) AddVars(vars ...Var) *Error
- func (xerr *Error) BadRequestViolations() []BadRequestViolation
- func (xerr *Error) DebugInfo() Optional[DebugInfo]
- func (xerr *Error) DomainType() string
- func (xerr *Error) Error() string
- func (xerr *Error) ErrorInfo() Optional[ErrorInfo]
- func (xerr *Error) HideDetails() *Error
- func (xerr *Error) IsDetailsHidden() bool
- func (xerr *Error) IsDirectlyRetryable() bool
- func (xerr *Error) IsDomainError(domain, reason string) bool
- func (xerr *Error) IsRetryableAtHigherLevel() bool
- func (xerr *Error) LogLevel() LogLevel
- func (xerr *Error) MarshalJSON() ([]byte, error)
- func (xerr *Error) PreconditionViolations() []PreconditionViolation
- func (xerr *Error) QuotaViolations() []QuotaViolation
- func (xerr *Error) RemoveSensitiveDetails() *Error
- func (xerr *Error) ResourceInfos() []ResourceInfo
- func (xerr *Error) RuntimeState() []Var
- func (xerr *Error) SetDebugInfo(detail string, stackEntries []string) *Error
- func (xerr *Error) SetErrorInfo(domain, reason string, metadata map[string]any) *Error
- func (xerr *Error) SetLogLevel(level LogLevel) *Error
- func (xerr *Error) SetStatus(s *status.Status) *Error
- func (xerr *Error) ShowDetails() *Error
- func (xerr *Error) Status() *status.Status
- func (xerr *Error) StatusCode() codes.Code
- func (xerr *Error) StatusMessage() string
- func (xerr *Error) StatusProto() *spb.Status
- type ErrorInfo
- type ErrorInfoOptions
- type LogLevel
- type Optional
- type PreconditionViolation
- type QuotaViolation
- type ResourceInfo
- type Var
- type WrappedError
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToAddErrorDetails = errors.New("failed to add error details")
Functions ¶
func DomainType ¶
DomainType returns a unique error type based on the domain and reason. This is used to enable switch-case statements.
func ErrorGuide ¶
func ErrorGuide() errorGuide
ErrorGuide implements a decision tree that helps developers choose the right error type for their use case. Errors are not supposed to be created using this guide, although it is possible. Instead, use the guide to find the right error type and then create the error using the appropriate factory function.
IMPORTANT! Each method has a comment that explains when to use the error type. Please read the comments carefully before choosing an error type.
func Init ¶
func Init(domain string)
Init initializes the package. It must called once, before creating any errors, and only be called at application startup-time. It is NOT thread-safe.
The domain is the logical grouping to which the "reason" belongs. See the Reason field in the unexported errorInfo struct for more information about the "reason". The error domain is typically the registered service name of the tool or product that generated the error. The domain must be a globally unique value.
- Example: pubsub.googleapis.com
func Wrap ¶
Wrap wrap errors with a message to add more context to the error. It is used when receiving an error from a call that is already an Error instance and you want to add more context to the error.
Ex.
err := pkg.Func() // returns an Error instance if err != nil { return errors.Wrap(err, "more context to err") }
Types ¶
type BadRequestViolation ¶
type BadRequestViolation struct { // Field is a path that leads to a field in the request body. The value will be a // sequence of dot-separated identifiers that identify a protocol buffer // field. // // Consider the following: // // message CreateContactRequest { // message EmailAddress { // enum Type { // TYPE_UNSPECIFIED = 0; // HOME = 1; // WORK = 2; // } // // optional string email = 1; // repeated EmailType type = 2; // } // // string full_name = 1; // repeated EmailAddress email_addresses = 2; // } // // In this example, in proto `field` could take one of the following values: // // - `full_name` for a violation in the `full_name` value // - `email_addresses[1].email` for a violation in the `email` field of the // first `email_addresses` message // - `email_addresses[3].type[2]` for a violation in the second `type` // value in the third `email_addresses` message. // // In JSON, the same values are represented as: // // - `fullName` for a violation in the `fullName` value // - `emailAddresses[1].email` for a violation in the `email` field of the // first `emailAddresses` message // - `emailAddresses[3].type[2]` for a violation in the second `type` // value in the third `emailAddresses` message. Field string // Description is a description of why the request element is bad. Description string }
BadRequestViolation is a message type used to describe a single bad request field.
type DebugInfo ¶
type DebugInfo struct { // Additional debugging information provided by the server. Detail string // The stack trace entries indicating where the error occurred. StackEntries []string }
Describes additional debugging info.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func From ¶
From returns an Error instance from an error. It's meant to be used in your application, at the place in the code where the error is logged.
If the error is not an Error instance, then it is an unexpected error and should be logged, so it can be discovered that there's code where the error isn't correctly handled.
func NewAborted ¶
func NewAborted(opts ErrorInfoOptions) *Error
NewAborted creates a new Aborted error.
For when to use this, see the ErrorGuide function for more information.
func NewAlreadyExists ¶
func NewAlreadyExists(info ResourceInfo) *Error
NewAlreadyExists creates a new AlreadyExists error.
For when to use this, see the ErrorGuide function for more information.
func NewAlreadyExistsBatch ¶
func NewAlreadyExistsBatch(infos []ResourceInfo) *Error
NewAlreadyExistsBatch creates a new AlreadyExists error. This is the batch version that adds information about multiple resources that already exist.
For when to use this, see the ErrorGuide function for more information.
func NewCancelled ¶
func NewCancelled() *Error
NewCancelled creates a new Cancelled error.
For when to use this, see the ErrorGuide function for more information.
func NewDeadlineExceeded ¶
func NewDeadlineExceeded() *Error
NewDeadlineExceeded creates a new DeadlineExceeded error.
For when to use this, see the ErrorGuide function for more information.
func NewInternal ¶
NewInternal creates a new Internal error.
For when to use this, see the ErrorGuide function for more information.
func NewInvalidArgument ¶
NewInvalidArgument creates a new InvalidArgument error.
Parameters:
Field: A path that leads to a field in the request body. The value will be a sequence of dot-separated identifiers that identify a protocol buffer field. Consider the following: message CreateContactRequest { message EmailAddress { enum Type { TYPE_UNSPECIFIED = 0; HOME = 1; WORK = 2; } optional string email = 1; repeated EmailType type = 2; } string full_name = 1; repeated EmailAddress email_addresses = 2; } In this example, in proto, `field` could take one of the following values: - `full_name` for a violation in the `full_name` value - `email_addresses[1].email` for a violation in the `email` field of the first `email_addresses` message - `email_addresses[3].type[2]` for a violation in the second `type` value in the third `email_addresses` message. In JSON, the same values are represented as: - `fullName` for a violation in the `fullName` value - `emailAddresses[1].email` for a violation in the `email` field of the first `emailAddresses` message - `emailAddresses[3].type[2]` for a violation in the second `type` value in the third `emailAddresses` message. Description: A description of why the request element is bad. See the below examples: - `fullName`: "The full name of the contact. It should include both first and last names. Example: `John Doe`". - `emailAddresses[3].type[2]`: "The type of the email address. It can be HOME, WORK, or unspecified. Example: [HOME, WORK]".
For when to use this error type, see the ErrorGuide function for more information.
func NewInvalidArgumentBatch ¶
func NewInvalidArgumentBatch(violations []BadRequestViolation) *Error
NewInvalidArgumentBatch creates a new InvalidArgument error. This is the batch version that adds multiple field violations.
For when to use this, see the ErrorGuide function for more information.
func NewNotFound ¶
func NewNotFound(info ResourceInfo) *Error
NewNotFound creates a new NotFound error.
For when to use this, see the ErrorGuide function for more information.
func NewNotFoundBatch ¶
func NewNotFoundBatch(infos []ResourceInfo) *Error
NewNotFoundBatch creates a new NotFound error. This is the batch version that adds information about multiple resources that were not found.
For when to use this, see the ErrorGuide function for more information.
func NewNotImplemented ¶
func NewNotImplemented() *Error
NewNotImplemented creates a new NotImplemented error.
For when to use this, see the ErrorGuide function for more information.
func NewOutOfRange ¶
NewOutOfRange creates a new OutOfRange error.
Parameters: see NewInvalidArgument
For when to use this, see the ErrorGuide function for more information.
func NewOutOfRangeBatch ¶
func NewOutOfRangeBatch(violations []BadRequestViolation) *Error
NewOutOfRangeBatch creates a new OutOfRange error. This is the batch version that adds multiple field violations.
For when to use this, see the ErrorGuide function for more information.
func NewPermissionDenied ¶
func NewPermissionDenied(opts ErrorInfoOptions) *Error
NewPermissionDenied creates a new PermissionDenied error.
For when to use this, see the ErrorGuide function for more information.
func NewPreconditionFailure ¶
NewFailedPrecondition creates a new FailedPrecondition error.
Parameters:
Description: Is a description of how the precondition failed. Developers can use this description to understand how to fix the failure. For example, "Terms of service not accepted". Subject: Is the subject, relative to the type, that failed. For example, "google.com/cloud" relative to the "TOS" type would indicate which terms of service is being referenced. Typ: Is the type of PreconditionFailure. It is recommended to use a service-specific enum type to define the supported precondition violation subjects. For example, "TOS" for "Terms of Service violation".
For when to use this error type, see the ErrorGuide function for more information.
func NewPreconditionFailureBatch ¶
func NewPreconditionFailureBatch(violations []PreconditionViolation) *Error
NewFailedPreconditionBatch creates a new FailedPrecondition error. This is the batch version that adds multiple precondition violations.
func NewQuotaFailure ¶
NewQuotaFailure creates a new QuotaFailure error, which is a specialized version of a resource exhausted error.
Parameters:
Subject: The subject on which the quota check failed. For example, "clientip:<ip address of client>" or "project:<Google developer project id>". Description: Description of how the quota check failed. Clients can use this description to find more about the quota configuration in the service's public documentation. For example: "Service disabled" or "Daily Limit for read operations exceeded".
For when to use this, see the ErrorGuide function for more information.
func NewQuotaFailureBatch ¶
func NewQuotaFailureBatch(violations []QuotaViolation) *Error
NewQuotaFailureBatch creates a new QuotaFailure error. This is the batch version that adds multiple quota violations.
For when to use this, see the ErrorGuide function for more information.
func NewRequestDataLoss ¶
func NewRequestDataLoss(opts ErrorInfoOptions) *Error
NewRequestDataLoss creates a new DataLoss error.
For when to use this, see the ErrorGuide function for more information.
func NewResourceExhausted ¶
func NewResourceExhausted(opts ErrorInfoOptions) *Error
NewResourceExhausted creates a new ResourceExhausted error.
For when to use this, see the ErrorGuide function for more information.
func NewServerDataLoss ¶
NewServerDataLoss creates a new DataLoss error.
For when to use this, see the ErrorGuide function for more information.
func NewUnauthenticated ¶
func NewUnauthenticated(opts ErrorInfoOptions) *Error
NewUnauthenticated creates a new Unauthenticated error.
For when to use this, see the ErrorGuide function for more information.
func NewUnavailable ¶
NewUnavailable creates a new Unavailable error.
For when to use this, see the ErrorGuide function for more information.
func NewUnknown ¶
NewUnknown creates a new Unknown error.
For when to use this, see the ErrorGuide function for more information.
func (*Error) AddBadRequestViolations ¶
func (xerr *Error) AddBadRequestViolations(violations []BadRequestViolation) *Error
AddBadRequestViolations adds a list of bad request violations to the error details. If the error details already contain bad request violations, the new ones are appended to the existing ones.
It is recommended to include a bad request violation for the following error types:
- INVALID_ARGUMENT
- OUT_OF_RANGE
See: https://cloud.google.com/apis/design/errors#error_payloads
func (*Error) AddPreconditionViolations ¶
func (xerr *Error) AddPreconditionViolations(violations []PreconditionViolation) *Error
AddPreconditionViolations adds a list of precondition violations to the error details. If the error details already contain precondition violations, the new ones are appended to the existing ones.
func (*Error) AddQuotaViolations ¶
func (xerr *Error) AddQuotaViolations(violations []QuotaViolation) *Error
AddQuotaViolations adds a list of quota violations to the error details. If the error details already contain quota violations, the new ones are appended to the existing ones.
func (*Error) AddResourceInfos ¶
func (xerr *Error) AddResourceInfos(infos []ResourceInfo) *Error
AddResourceInfos adds resource info details to the error details. If the error details already contain a resource info detail, it is overwritten.
It is recommended to include a resource info detail for the following error types:
- NOT_FOUND
- ALREADY_EXISTS
See: https://cloud.google.com/apis/design/errors#error_payloads
func (*Error) BadRequestViolations ¶
func (xerr *Error) BadRequestViolations() []BadRequestViolation
BadRequestViolations returns a list of bad request violations. If the error details do not contain bad request violations, it returns nil.
func (*Error) DebugInfo ¶
DebugInfo returns the error info details. If the error details do not contain error info details, it returns an invalid optional.
func (*Error) DomainType ¶
DomainType returns a unique error type based on the domain and reason. This is used to enable switch-case statements.
Ex.
err := othersystempb.SomeMethod(ctx, req) if err != nil { xerr := grpc.XErrorFrom(err) switch xerr.DomainType() { case xerror.DomainType(othersystemerror.Domain, othersystemerror.NO_STOCK): requestMoreStock() // decision based on the error type
func (*Error) ErrorInfo ¶
ErrorInfo returns the error info details. If the error details do not contain error info details, it returns an invalid optional.
func (*Error) HideDetails ¶
HideDetails marks the error as having hidden details. This is useful when you want to hide the details of the error from external callers. Effectively, this means that the "debug info" and "error info" details are removed from the error when returned to the caller. For this to work, the server has to use the implementation-specific functionality such as the unary interceptor for gRPC.
func (*Error) IsDetailsHidden ¶
IsDetailsHidden returns true if the error details are hidden, otherwise it returns false.
func (*Error) IsDirectlyRetryable ¶
IsDirectlyRetryable returns true if the call that caused the error is directly retryable, otherwise it returns false. Retries should be attempted using an exponential backoff strategy.
func (*Error) IsDomainError ¶
IsDomainError compares the error with the provided domain-specific error details (the domain and reason). The reason is machine-readable and most importantly, it is unique within a particular domain of errors. This method is used to check if a returned error is a particular domain-specific error. This is useful when decisions need to be made based on the error type.
Note! Sometimes, decisions can be made based on the status code alone, but when that is not granular enough, the domain and reason should be used to make decisions.
Ex.
err := othersystempb.SomeMethod(ctx, req) if err != nil { xerr := xgrpc.ErrorFrom(err) if xerr.IsDomainError(othersystem.Domain, othersystem.NO_STOCK) { requestMoreStock() // decision based on the error type } }
func (*Error) IsRetryableAtHigherLevel ¶
IsRetryableAtHigherLevel returns true if the call that caused the error cannot be directly retried, but instead should be retried at a higher level in the system. Example: an optimistic concurrency error in a database transaction, where the whole transaction should be retried, not just the failing part.
func (*Error) MarshalJSON ¶
MarshalJSON marshals the error to JSON. This is only useful for testing purposes to be able to generate golden files to be able to inspect the error in a human-readable format.
func (*Error) PreconditionViolations ¶
func (xerr *Error) PreconditionViolations() []PreconditionViolation
PreconditionsViolations returns a list of precondition violations. If the error details do not contain precondition violations, it returns nil.
func (*Error) QuotaViolations ¶
func (xerr *Error) QuotaViolations() []QuotaViolation
QuotaViolations returns a list of quota violations. If the error details do not contain quota violations, it returns nil.
func (*Error) RemoveSensitiveDetails ¶
RemoveSensitiveDetails removes sensitive details from the error. This is useful when you want to return the error to the client, but you don't want to expose sensitive details such as debug info or error info.
func (*Error) ResourceInfos ¶
func (xerr *Error) ResourceInfos() []ResourceInfo
ResourceInfos returns a list of resource info details. If the error details do not contain resource info details, it returns nil.
func (*Error) RuntimeState ¶
RuntimeState returns the runtime state of the error. This is used when you want to log the circumstances when the error was encountered.
func (*Error) SetDebugInfo ¶
SetDebugInfoDetail sets debug info detail to the error details. If the error details already contain a debug info detail, it is overwritten. If the detail is empty, the operation is a no-op.
It is NOT recommended to include a debug info detail since it'll be returned to the caller. If you need to log debug info, use the runtime state instead (the AddVar() and AddVars() methods). It's is however possible to include a debug info detail and still not return it to the caller by calling the HideDetails() method.
func (*Error) SetErrorInfo ¶
SetErrorInfo sets error info details to the error details. If the error details already contain error info details, they are overwritten. If the domain is empty, the domain is set to the package's default domain which should be set at startup-time by calling the Init() function.
It is recommended to include an error info detail for the following error types:
- UNAUTHENTICATED
- PERMISSION_DENIED
- ABORTED
See: https://cloud.google.com/apis/design/errors#error_payloads
func (*Error) SetLogLevel ¶
SetLogLevel sets the log level of the error.
func (*Error) ShowDetails ¶
ShowDetails marks the error as having shown details. This is the inverse of HideDetails.
func (*Error) StatusCode ¶
func (*Error) StatusMessage ¶
func (*Error) StatusProto ¶
StatusProto returns the status proto contained in the error.
type ErrorInfo ¶
type ErrorInfo struct { // Domain is the logical grouping to which the "reason" belongs. The error domain is typically the registered // service name of the tool or product that generated the error. The domain must be a globally unique value. Domain string // Reason is a short snake_case description of why the error occurred. Error reasons are unique within a particular // domain of errors. The application should define an enum of error reasons. // // The reason should have these properties: // - Be meaningful enough for a human reader to understand what the reason refers to. // - Be unique and consumable by machine actors for automation. // - Example: CPU_AVAILABILITY // - Distill your error message into its simplest form. For example, the reason string could be one of the // following text examples in UPPER_SNAKE_CASE: UNAVAILABLE, NO_STOCK, CHECKED_OUT, AVAILABILITY_ERROR, if your // error message is: // The Book, "The Great Gatsby", is unavailable at the Library, "Garfield East". It is expected to be available // again on 2199-05-13. Reason string // Metadata is additional structured details about this error, which should provide important context for clients // to identify resolution steps. Keys should be in lower camel-case, and be limited to 64 characters in length. // When identifying the current value of an exceeded limit, the units should be contained in the key, not the value. // // Example: {"vmType": "e2-medium", "attachment": "local-ssd=3,nvidia-t4=2", "zone": us-east1-a"} Metadata map[string]string }
ErrorInfo describes the cause of the error with structured details.
Example of an error when contacting the "pubsub.googleapis.com" API when it is not enabled:
{ "reason": "API_DISABLED", "domain": "googleapis.com", "metadata": { "resource": "projects/123", "service": "pubsub.googleapis.com" } }
This response indicates that the pubsub.googleapis.com API is not enabled. Example of an error that is returned when attempting to create a Spanner instance in a region that is out of stock:
{ "reason": "STOCKOUT", "domain": "spanner.googleapis.com", "metadata": { "availableRegions": "us-central1,us-east2" } }
type ErrorInfoOptions ¶
type ErrorInfoOptions struct { // Error is the error that occurred. Error error // Reason is a short snake_case description of why the error occurred. Error reasons are unique within a particular // domain of errors. The application should define an enum of error reasons. // // The reason should have these properties: // - Be meaningful enough for a human reader to understand what the reason refers to. // - Be unique and consumable by machine actors for automation. // - Example: CPU_AVAILABILITY // - Distill your error message into its simplest form. For example, the reason string could be one of the // following text examples in UPPER_SNAKE_CASE: UNAVAILABLE, NO_STOCK, CHECKED_OUT, AVAILABILITY_ERROR, if your // error message is: // The Book, "The Great Gatsby", is unavailable at the Library, "Garfield East". It is expected to be available // again on 2199-05-13. Reason string // Metadata is additional structured details about this error, which should provide important context for clients // to identify resolution steps. Keys should be in lower camel-case, and be limited to 64 characters in length. // When identifying the current value of an exceeded limit, the units should be contained in the key, not the value. // // Example: {"vmType": "e2-medium", "attachment": "local-ssd=3,nvidia-t4=2", "zone": us-east1-a"} Metadata map[string]any }
type LogLevel ¶
type LogLevel uint8
LogLevel is used to control the way the error is logged. For example as an error, warning, notice etc.
type Optional ¶
type Optional[T any] struct { // Value is the value that may or may not be present. Value T // Valid is true if the value is present, otherwise it is false. Valid bool }
Optional is a type used to model a value that may or may not be present. It is used to model the return value of a function that may return a value or not. It is used to avoid returning nil values.
type PreconditionViolation ¶
type PreconditionViolation struct { // Description is a description of how the precondition failed. Developers can use this // description to understand how to fix the failure. // // For example: "Terms of service not accepted". Description string // Subject is the subject, relative to the type, that failed. // For example, "google.com/cloud" relative to the "TOS" type would indicate // which terms of service is being referenced. Subject string // Typ is the type of PreconditionFailure. It's recommended using a service-specific // enum type to define the supported precondition violation subjects. For // example, "TOS" for "Terms of Service violation". Typ string }
PreconditionViolation is a message type used to describe a single precondition failure.
type QuotaViolation ¶
type QuotaViolation struct { //Subject on which the quota check failed. // For example, "clientip:<ip address of client>" or "project:<Google // developer project id>". Subject string // Descriptions is a description of how the quota check failed. Clients can use this // description to find more about the quota configuration in the service's // public documentation, or find the relevant quota limit to adjust through // developer console. // // For example: "Service disabled" or "Daily Limit for read operations // exceeded". Description string }
QuotaViolation is a message type used to describe a single quota violation. For example, a daily quota or a custom quota that was exceeded.
type ResourceInfo ¶
type ResourceInfo struct { // Description describes what error is encountered when accessing this resource. // For example, updating a cloud project may require the `writer` permission // on the developer console project. Description string // ResourceName is the name of the resource being accessed. For example, a shared calendar // name: "example.com_4fghdhgsrgh@group.calendar.google.com", if the current // error is // [google.rpc.Code.PERMISSION_DENIED][google.rpc.Code.PERMISSION_DENIED]. ResourceName string // ResourceType is a name for the type of resource being accessed, e.g. "sql table", // "cloud storage bucket", "file", "Google calendar"; or the type URL // of the resource: e.g. "type.googleapis.com/google.pubsub.v1.Topic". ResourceType string // Owner is the owner of the resource (optional). // For example, "user:<owner email>" or "project:<Google developer project // id>". Owner string }
ResourceInfo describes the resource that is being accessed.
type Var ¶
Var models what the circumstances were when the error was encountered and is used to provide additional context to the error. Its purpose is to be logged and thereby give context to the error in the logs.
type WrappedError ¶
WrappedError is a model that makes it easy to add more context to an error as it is passed up the call stack.
func (*WrappedError) AddVar ¶
func (wr *WrappedError) AddVar(name string, value any) *WrappedError
AddVar adds runtime state information to the wrapped Error instance, if there is one.
func (*WrappedError) AddVars ¶
func (wr *WrappedError) AddVars(vars ...Var) *WrappedError
AddVars adds multiple runtime state information to the wrapped Error instance, if there is one.
func (*WrappedError) Error ¶
func (wr *WrappedError) Error() string
func (*WrappedError) Unwrap ¶
func (wr *WrappedError) Unwrap() error
Unwrap returns the directly wrapped error.
func (*WrappedError) XError ¶
func (wr *WrappedError) XError() *Error
XError returns the Error instance that is wrapped by the WrappedError instance, if there is one. Otherwise, it returns nil.