errors

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 9 Imported by: 10

README

go-errors

CircleCI GoDoc |

Package errors is a robust and easy-to-use error package. It supports verbosity levels, maintains causal errors, implements stack tracing, maps to common HTTP error codes, exposes temporary and timeout errors, implements JSON marshalling, and is GRPC compatible.

This package started github.com/goware/errorx and grew from there.

Supported errors are as follows:

Error | HTTP Code | Description

AbortedError | 409 CONFLICT | operation was aborted AlreadyExistsError | 409 CONFLICT | attempt to create an entity failed because one already exists CanceledError | 499 CLIENT CLOSED REQUEST | operation was canceled DataLossError | 500 INTERNAL SERVER ERROR | unrecoverable data loss or corruption DeadlineExceededError | 504 GATEWAY TIMEOUT | operation expired before completion FailedPreconditionError | 400 BAD REQUEST | operation rejected because system is not in a state required for operation's execution InternalError | 500 INTERNAL SERVER ERROR | some invariants expected by underlying system has been broken InvalidArgumentError | 400 BAD REQUEST | client specified an invalid argument NotFoundError | 404 NOT FOUND | requested entity was not found NotImplementedError | 501 NOT IMPLEMENTED | operation is not implemented OutOfRangeError | 400 BAD REQUEST | operation was attempted past the valid range NewPassthroughError | varies | passes 400 errors directly, 500 errors are mapped to InternalError PermissionDeniedError | 403 FORBIDDEN | the caller does not have permission to execute the specified operation ResourceExhaustedError | 429 TOO MANY REQUESTS | some resource has been exhausted UnauthenticatedError | 401 UNAUTHORIZED | the request does not have valid authentication credentials UnavailableError | 503 SERVICE UNAVAILABLE | the service is currently unavailable UnknownError | 500 INTERNAL SERVER ERROR | unknown server error

Documentation

Overview

Package errors is a robust and easy-to-use error package. It supports verbosity levels, maintains causal errors, implements stack tracing, maps to common HTTP error codes, exposes temporary and timeout errors, implements JSON marshalling, and is GRPC compatible.

Index

Constants

View Source
const (
	Info = iota
	Verbose
	Debug
	Trace
)

Constants for use with SetVerbosity(...)

Variables

This section is empty.

Functions

func NewPassthroughError

func NewPassthroughError(msg string, err error) error

NewPassthroughError handles an error from an external dependency. If the error is a timeout, canceled, unavailable, unknown, or temporary error, it is passed through as the appropriate correlating type from this package. Otherwise, an internal error with the provided message is returned.

func SetVerbosity

func SetVerbosity(v int)

SetVerbosity changes global verbosity setting.

Types

type AbortedError

type AbortedError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

AbortedError indicates the operation was aborted, typically due to a concurrency issue like sequencer check failures, transaction aborts, etc.

A litmus test that may help a service implementor in deciding between ResourceExhaustedError, UnavailableError, and AbortedError:

(a) Use ResourceExhaustedError for client errors like exceeding allowed
    rate limits. The client may retry the failing call after they have
    resolved the causal issue.
(b) Use UnavailableError for server errors like inability to accomodate
    current load or planned server maintenance. The client may retry the
    failing call.
(c) Use AbortedError if the client should retry at a higher-level
    (e.g., restarting a read-modify-write sequence).

Example error Message:

ABORTED. Couldn’t acquire lock on resource ‘xxx’.

HTTP Mapping: 409 CONFLICT

RPC Mapping: ABORTED

func NewAbortedError

func NewAbortedError(Message string, cause ...error) *AbortedError

NewAbortedError returns a new AbortedError.

func (*AbortedError) Error

func (e *AbortedError) Error() string

Error implements the error interface

func (*AbortedError) GRPCStatus

func (e *AbortedError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*AbortedError) GetCause

func (e *AbortedError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*AbortedError) GetCode

func (e *AbortedError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*AbortedError) GetMessage

func (e *AbortedError) GetMessage() string

GetMessage returns the message associated with this error.

func (*AbortedError) GetStack

func (e *AbortedError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*AbortedError) Temporary

func (e *AbortedError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*AbortedError) Timeout

func (e *AbortedError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type AlreadyExistsError

type AlreadyExistsError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

AlreadyExistsError means an attempt to create an entity failed because one already exists.

Example error Message:

ALREADY EXISTS. Resource 'xxx' already exists.

HTTP Mapping: 409 CONFLICT

RPC Mapping: ALREADY_EXISTS

func NewAlreadyExistsError

func NewAlreadyExistsError(Message string, cause ...error) *AlreadyExistsError

NewAlreadyExistsError returns a new AlreadyExistsError.

func (*AlreadyExistsError) Error

func (e *AlreadyExistsError) Error() string

Error implements the error interface

func (*AlreadyExistsError) GRPCStatus

func (e *AlreadyExistsError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*AlreadyExistsError) GetCause

func (e *AlreadyExistsError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*AlreadyExistsError) GetCode

func (e *AlreadyExistsError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*AlreadyExistsError) GetMessage

func (e *AlreadyExistsError) GetMessage() string

GetMessage returns the message associated with this error.

func (*AlreadyExistsError) GetStack

func (e *AlreadyExistsError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*AlreadyExistsError) Temporary

func (e *AlreadyExistsError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*AlreadyExistsError) Timeout

func (e *AlreadyExistsError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type CanceledError

type CanceledError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

CanceledError indicates the operation was canceled (typically by the caller).

Example error Message:

CANCELED.

HTTP Mapping: 499 CLIENT CLOSED REQUEST

RPC Mapping: CANCELED

func NewCanceledError

func NewCanceledError(Message string, cause ...error) *CanceledError

NewCanceledError returns a new CanceledError.

func (*CanceledError) Error

func (e *CanceledError) Error() string

Error implements the error interface

func (*CanceledError) GRPCStatus

func (e *CanceledError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*CanceledError) GetCause

func (e *CanceledError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*CanceledError) GetCode

func (e *CanceledError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*CanceledError) GetMessage

func (e *CanceledError) GetMessage() string

GetMessage returns the message associated with this error.

func (*CanceledError) GetStack

func (e *CanceledError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*CanceledError) Temporary

func (e *CanceledError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*CanceledError) Timeout

func (e *CanceledError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type DataLossError

type DataLossError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

DataLossError indicates unrecoverable data loss or corruption.

Since the client cannot fix this server error, it is not useful to generate additional error details. To avoid leaking sensitive information under error conditions, only a generic error Message is marshalled to JSON or returned via GRPC status.

Error Message:

DATA LOSS. Unrecoverable data loss or data corruption.

HTTP Mapping: 500 INTERNAL SERVER ERROR

RPC Mapping: DATA_LOSS

func NewDataLossError

func NewDataLossError(Message string, cause ...error) *DataLossError

NewDataLossError returns a new DataLossError.

func (*DataLossError) Error

func (e *DataLossError) Error() string

Error implements the error interface

func (*DataLossError) GRPCStatus

func (e *DataLossError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*DataLossError) GetCause

func (e *DataLossError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*DataLossError) GetCode

func (e *DataLossError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*DataLossError) GetMessage

func (e *DataLossError) GetMessage() string

GetMessage returns the message associated with this error.

func (*DataLossError) GetStack

func (e *DataLossError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*DataLossError) Temporary

func (e *DataLossError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*DataLossError) Timeout

func (e *DataLossError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type DeadlineExceededError

type DeadlineExceededError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

DeadlineExceededError means operation expired before completion. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire.

Since the client cannot fix this server error, it is not useful to generate additional error details. To avoid leaking sensitive information under error conditions, only a generic error Message is marshalled to JSON or returned via GRPC status.

Error Message:

DEADLINE EXCEEDED. Server timeout.

HTTP Mapping: 504 GATEWAY TIMEOUT

RPC Mapping: DEADLINE_EXCEEDED

func NewDeadlineExceededError

func NewDeadlineExceededError(Message string, cause ...error) *DeadlineExceededError

NewDeadlineExceededError returns a new DeadlineExceededError.

func (*DeadlineExceededError) Error

func (e *DeadlineExceededError) Error() string

Error implements the error interface

func (*DeadlineExceededError) GRPCStatus

func (e *DeadlineExceededError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*DeadlineExceededError) GetCause

func (e *DeadlineExceededError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*DeadlineExceededError) GetCode

func (e *DeadlineExceededError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*DeadlineExceededError) GetMessage

func (e *DeadlineExceededError) GetMessage() string

GetMessage returns the message associated with this error.

func (*DeadlineExceededError) GetStack

func (e *DeadlineExceededError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*DeadlineExceededError) Temporary

func (e *DeadlineExceededError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*DeadlineExceededError) Timeout

func (e *DeadlineExceededError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type Errors

type Errors struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Errors is a container for multiple errors and implements the error interface

func NewErrors

func NewErrors(errs ...error) *Errors

NewErrors returns an error that consists of multiple errors.

func (*Errors) Append

func (e *Errors) Append(errs ...error)

Pop removes and returns the last error from Errors

func (Errors) Error

func (e Errors) Error() string

Error implements the error interface

func (*Errors) GRPCStatus

func (e *Errors) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*Errors) GetCause

func (e *Errors) GetCause() error

GetCause returns any causal errors associated with this error.

func (*Errors) GetCode

func (e *Errors) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*Errors) GetMessage

func (e *Errors) GetMessage() string

GetMessage returns the message associated with this error.

func (*Errors) GetStack

func (e *Errors) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*Errors) Len

func (e *Errors) Len() int

Len returns the number of errors in e

func (*Errors) Merge

func (e *Errors) Merge(in *Errors)

Merge adds in to e

func (*Errors) Pop

func (e *Errors) Pop() error

Pop removes and returns the last error from Errors

func (*Errors) Shift

func (e *Errors) Shift() error

Shift removes and returns the first error from Errors

func (*Errors) Temporary

func (e *Errors) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*Errors) Timeout

func (e *Errors) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type FailedPreconditionError

type FailedPreconditionError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

FailedPreconditionError indicates operation was rejected because the system is not in a state required for the operation's execution. For example, directory to be deleted may be non-empty, an rmdir operation is applied to a non-directory, etc.

Service implementors can use the following guidelines to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call. (b) Use ABORTED if the client should retry at a higher level (e.g., when a client-specified test-and-set fails, indicating the client should restart a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until the system state has been explicitly fixed. E.g., if an "rmdir" fails because the directory is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless the files are deleted from the directory.

Example error Message:

FAILED PRECONDITION. Resource xxx is a non-empty directory, so it cannot be deleted.

HTTP Mapping: 400 BAD REQUEST

RPC Mapping: FAILED_PRECONDITION

func NewFailedPreconditionError

func NewFailedPreconditionError(Message string, cause ...error) *FailedPreconditionError

NewFailedPreconditionError returns a new FailedPreconditionError.

func (*FailedPreconditionError) Error

func (e *FailedPreconditionError) Error() string

Error implements the error interface

func (*FailedPreconditionError) GRPCStatus

func (e *FailedPreconditionError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*FailedPreconditionError) GetCause

func (e *FailedPreconditionError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*FailedPreconditionError) GetCode

func (e *FailedPreconditionError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*FailedPreconditionError) GetMessage

func (e *FailedPreconditionError) GetMessage() string

GetMessage returns the message associated with this error.

func (*FailedPreconditionError) GetStack

func (e *FailedPreconditionError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*FailedPreconditionError) Temporary

func (e *FailedPreconditionError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*FailedPreconditionError) Timeout

func (e *FailedPreconditionError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type InternalError

type InternalError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

InternalError means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken.

A litmus test that may help a service implementor in deciding between UnknownError and InternalError:

(a) Use UnknownError for generic server-side errors that may be recoverable
    (UnknownError.Temporary() will return true).
(b) Use InternalError for generic server-side errors that are not recoverable
    (InternalError.Temporary() will return false).

Since the client cannot fix this server error, it is not useful to generate additional error details. To avoid leaking sensitive information under error conditions, only a generic error Message is marshalled to JSON or returned via GRPC status.

Error Message:

INTERNAL ERROR.

HTTP Mapping: 500 INTERNAL SERVER ERROR

RPC Mapping: INTERNAL

func NewInternalError

func NewInternalError(Message string, cause ...error) *InternalError

NewInternalError returns a new InternalError.

func (*InternalError) Error

func (e *InternalError) Error() string

Error implements the error interface

func (*InternalError) GRPCStatus

func (e *InternalError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*InternalError) GetCause

func (e *InternalError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*InternalError) GetCode

func (e *InternalError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*InternalError) GetMessage

func (e *InternalError) GetMessage() string

GetMessage returns the message associated with this error.

func (*InternalError) GetStack

func (e *InternalError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*InternalError) Temporary

func (e *InternalError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*InternalError) Timeout

func (e *InternalError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type InvalidArgumentError

type InvalidArgumentError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

InvalidArgumentError indicates client specified an invalid argument. Note that this differs from FailedPreconditionError. It indicates arguments that are problematic regardless of the state of the system (e.g., a malformed file name).

Example error Message:

INVALID ARGUMENT. Request field x.y.z is xxx, expected one of [yyy, zzz].

HTTP Mapping: 400 BAD REQUEST

RPC Mapping: INVALID_ARGUMENT

func NewInvalidArgumentError

func NewInvalidArgumentError(Message string, cause ...error) *InvalidArgumentError

NewInvalidArgumentError returns a new InvalidArgumentError.

func (*InvalidArgumentError) Error

func (e *InvalidArgumentError) Error() string

Error implements the error interface

func (*InvalidArgumentError) GRPCStatus

func (e *InvalidArgumentError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*InvalidArgumentError) GetCause

func (e *InvalidArgumentError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*InvalidArgumentError) GetCode

func (e *InvalidArgumentError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*InvalidArgumentError) GetMessage

func (e *InvalidArgumentError) GetMessage() string

GetMessage returns the message associated with this error.

func (*InvalidArgumentError) GetStack

func (e *InvalidArgumentError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*InvalidArgumentError) Temporary

func (e *InvalidArgumentError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*InvalidArgumentError) Timeout

func (e *InvalidArgumentError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type NotFoundError

type NotFoundError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

NotFoundError means some requested entity (e.g., file or directory) was not found.

Example error Message:

NOT FOUND. Resource 'xxx' not found.

HTTP Mapping: 404 NOT FOUND

RPC Mapping: NOT_FOUND

func NewNotFoundError

func NewNotFoundError(Message string, cause ...error) *NotFoundError

NewNotFoundError returns a new NotFoundError.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error implements the error interface

func (*NotFoundError) GRPCStatus

func (e *NotFoundError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*NotFoundError) GetCause

func (e *NotFoundError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*NotFoundError) GetCode

func (e *NotFoundError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*NotFoundError) GetMessage

func (e *NotFoundError) GetMessage() string

GetMessage returns the message associated with this error.

func (*NotFoundError) GetStack

func (e *NotFoundError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*NotFoundError) Temporary

func (e *NotFoundError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*NotFoundError) Timeout

func (e *NotFoundError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type NotImplementedError

type NotImplementedError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

NotImplementedError indicates operation is not implemented or not supported/enabled in this service.

Example error Message:

NOT IMPLEMENTED. Method 'xxx' not implemented.

HTTP Mapping: 501 NOT IMPLEMENTED

RPC Mapping: NOT_IMPLEMENTED

func NewNotImplementedError

func NewNotImplementedError(Message string, cause ...error) *NotImplementedError

NewNotImplementedError returns a new NotImplementedError.

func (*NotImplementedError) Error

func (e *NotImplementedError) Error() string

Error implements the error interface

func (*NotImplementedError) GRPCStatus

func (e *NotImplementedError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*NotImplementedError) GetCause

func (e *NotImplementedError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*NotImplementedError) GetCode

func (e *NotImplementedError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*NotImplementedError) GetMessage

func (e *NotImplementedError) GetMessage() string

GetMessage returns the message associated with this error.

func (*NotImplementedError) GetStack

func (e *NotImplementedError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*NotImplementedError) Temporary

func (e *NotImplementedError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*NotImplementedError) Timeout

func (e *NotImplementedError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type OutOfRangeError

type OutOfRangeError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

OutOfRangeError means operation was attempted past the valid range. E.g., seeking or reading past end of file.

Unlike InvalidArgumentError, this error indicates a problem that may be fixed if the system state changes. For example, a 32-bit file system will generate InvalidArgument if asked to read at an offset that is not in the range [0,2^32-1], but it will generate OutOfRangeError if asked to read from an offset past the current file size.

There is a fair bit of overlap between FailedPreconditionError and OutOfRangeError. We recommend using OutOfRangeError (the more specific error) when it applies so that callers who are iterating through a space can easily look for an OutOfRangeError to detect when they are done.

Example error Message:

OUT OF RANGE. Parameter 'age' is out of range [0, 125].

HTTP Mapping: 400 BAD REQUEST

RPC Mapping: OUT_OF_RANGE

func NewOutOfRangeError

func NewOutOfRangeError(Message string, cause ...error) *OutOfRangeError

NewOutOfRangeError returns a new OutOfRangeError.

func (*OutOfRangeError) Error

func (e *OutOfRangeError) Error() string

Error implements the error interface

func (*OutOfRangeError) GRPCStatus

func (e *OutOfRangeError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*OutOfRangeError) GetCause

func (e *OutOfRangeError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*OutOfRangeError) GetCode

func (e *OutOfRangeError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*OutOfRangeError) GetMessage

func (e *OutOfRangeError) GetMessage() string

GetMessage returns the message associated with this error.

func (*OutOfRangeError) GetStack

func (e *OutOfRangeError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*OutOfRangeError) Temporary

func (e *OutOfRangeError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*OutOfRangeError) Timeout

func (e *OutOfRangeError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type PermissionDeniedError

type PermissionDeniedError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

PermissionDeniedError indicates the caller does not have permission to execute the specified operation. It must not be used for rejections caused by exhausting some resource (use ResourceExhaustedError instead for those errors). It must not be used if the caller cannot be identified (use UnauthenticatedError instead for those errors).

Example error Message:

PERMISSION DENIED. Permission 'xxx' denied on file 'yyy'.

HTTP Mapping: 403 FORBIDDEN

RPC Mapping: PERMISSION_DENIED

func NewPermissionDeniedError

func NewPermissionDeniedError(Message string, cause ...error) *PermissionDeniedError

NewPermissionDeniedError returns a new PermissionDeniedError.

func (*PermissionDeniedError) Error

func (e *PermissionDeniedError) Error() string

Error implements the error interface

func (*PermissionDeniedError) GRPCStatus

func (e *PermissionDeniedError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*PermissionDeniedError) GetCause

func (e *PermissionDeniedError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*PermissionDeniedError) GetCode

func (e *PermissionDeniedError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*PermissionDeniedError) GetMessage

func (e *PermissionDeniedError) GetMessage() string

GetMessage returns the message associated with this error.

func (*PermissionDeniedError) GetStack

func (e *PermissionDeniedError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*PermissionDeniedError) Temporary

func (e *PermissionDeniedError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*PermissionDeniedError) Timeout

func (e *PermissionDeniedError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type ResourceExhaustedError

type ResourceExhaustedError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

ResourceExhaustedError indicates some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.

A litmus test that may help a service implementor in deciding between ResourceExhaustedError, UnavailableError, and AbortedError:

(a) Use ResourceExhaustedError for client errors like exceeding allowed
    rate limits. The client may retry the failing call after they have
    resolved the causal issue.
(b) Use UnavailableError for server errors like inability to accomodate
    current load or planned server maintenance. The client may retry the
    failing call.
(c) Use AbortedError if the client should retry at a higher-level
    (e.g., restarting a read-modify-write sequence).

Example error Message:

RESOURCE EXHAUSTED. Quota limit 'xxx' exceeded.

HTTP Mapping: 429 TOO MANY REQUESTS

RPC Mapping: RESOURCE_EXHAUSTED

func NewResourceExhaustedError

func NewResourceExhaustedError(Message string, cause ...error) *ResourceExhaustedError

NewResourceExhaustedError returns a new ResourceExhaustedError.

func (*ResourceExhaustedError) Error

func (e *ResourceExhaustedError) Error() string

Error implements the error interface

func (*ResourceExhaustedError) GRPCStatus

func (e *ResourceExhaustedError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*ResourceExhaustedError) GetCause

func (e *ResourceExhaustedError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*ResourceExhaustedError) GetCode

func (e *ResourceExhaustedError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*ResourceExhaustedError) GetMessage

func (e *ResourceExhaustedError) GetMessage() string

GetMessage returns the message associated with this error.

func (*ResourceExhaustedError) GetStack

func (e *ResourceExhaustedError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*ResourceExhaustedError) Temporary

func (e *ResourceExhaustedError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*ResourceExhaustedError) Timeout

func (e *ResourceExhaustedError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type UnauthenticatedError

type UnauthenticatedError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

UnauthenticatedError indicates the request does not have valid authentication credentials for the operation.

Example error Message:

UNAUTHENTICATED. Invalid authentication credentials.

HTTP Mapping: 401 UNAUTHORIZED

RPC Mapping: UNAUTHENTICATED

func NewUnauthenticatedError

func NewUnauthenticatedError(Message string, cause ...error) *UnauthenticatedError

NewUnauthenticatedError returns a new UnauthenticatedError.

func (*UnauthenticatedError) Error

func (e *UnauthenticatedError) Error() string

Error implements the error interface

func (*UnauthenticatedError) GRPCStatus

func (e *UnauthenticatedError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*UnauthenticatedError) GetCause

func (e *UnauthenticatedError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*UnauthenticatedError) GetCode

func (e *UnauthenticatedError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*UnauthenticatedError) GetMessage

func (e *UnauthenticatedError) GetMessage() string

GetMessage returns the message associated with this error.

func (*UnauthenticatedError) GetStack

func (e *UnauthenticatedError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*UnauthenticatedError) Temporary

func (e *UnauthenticatedError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*UnauthenticatedError) Timeout

func (e *UnauthenticatedError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type UnavailableError

type UnavailableError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

UnavailableError indicates the service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.

A litmus test that may help a service implementor in deciding between ResourceExhaustedError, UnavailableError, and AbortedError:

(a) Use ResourceExhaustedError for client errors like exceeding allowed
    rate limits. The client may retry the failing call after they have
    resolved the causal issue.
(b) Use UnavailableError for server errors like inability to accomodate
    current load or planned server maintenance. The client may retry the
    failing call.
(c) Use AbortedError if the client should retry at a higher-level
    (e.g., restarting a read-modify-write sequence).

Since the client cannot fix this server error, it is not useful to generate additional error details. To avoid leaking sensitive information under error conditions, only a generic error Message is marshalled to JSON or returned via GRPC status.

Error Message:

UNAVAILABLE. Unable to handle the request due to a temporary overloading or maintenance.

HTTP Mapping: 503 SERVICE UNAVAILABLE

RPC Mapping: UNAVAILABLE

func NewUnavailableError

func NewUnavailableError(Message string, cause ...error) *UnavailableError

NewUnavailableError returns a new UnavailableError.

func (*UnavailableError) Error

func (e *UnavailableError) Error() string

Error implements the error interface

func (*UnavailableError) GRPCStatus

func (e *UnavailableError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*UnavailableError) GetCause

func (e *UnavailableError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*UnavailableError) GetCode

func (e *UnavailableError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*UnavailableError) GetMessage

func (e *UnavailableError) GetMessage() string

GetMessage returns the message associated with this error.

func (*UnavailableError) GetStack

func (e *UnavailableError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*UnavailableError) Temporary

func (e *UnavailableError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*UnavailableError) Timeout

func (e *UnavailableError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

type UnknownError

type UnknownError struct {
	Code    int    `json:"errorCode"`
	Message string `json:"errorMessage"`
	// contains filtered or unexported fields
}

UnknownError is an unknown server error. An example of where this error may be returned is if a Status value received from another address space belongs to an error-space that is not known in this address space.

A litmus test that may help a service implementor in deciding between UnknownError and InternalError:

(a) Use UnknownError for generic server-side errors that may be recoverable
    (UnknownError.Temporary() will return true).
(b) Use InternalError for generic server-side errors that are not recoverable
    (InternalError.Temporary() will return false).

Since the client cannot fix this server error, it is not useful to generate additional error details. To avoid leaking sensitive information under error conditions, only a generic error Message is marshalled to JSON or returned via GRPC status.

Error Message:

UNKNOWN ERROR.

HTTP Mapping: 500 INTERNAL SERVER ERROR

RPC Mapping: UNKNOWN

func NewUnknownError

func NewUnknownError(Message string, cause ...error) *UnknownError

NewUnknownError returns a new UnknownError.

func (*UnknownError) Error

func (e *UnknownError) Error() string

Error implements the error interface

func (*UnknownError) GRPCStatus

func (e *UnknownError) GRPCStatus() *status.Status

GRPCStatus implements an interface required to return proper GRPC status codes

func (*UnknownError) GetCause

func (e *UnknownError) GetCause() error

GetCause returns any causal errors associated with this error.

func (*UnknownError) GetCode

func (e *UnknownError) GetCode() int

GetCode returns the HTTP status code associated with this error.

func (*UnknownError) GetMessage

func (e *UnknownError) GetMessage() string

GetMessage returns the message associated with this error.

func (*UnknownError) GetStack

func (e *UnknownError) GetStack() stack

GetStack returns the trace stack associated with this error.

func (*UnknownError) Temporary

func (e *UnknownError) Temporary() bool

Temporary indicates if this error is potentially recoverable.

func (*UnknownError) Timeout

func (e *UnknownError) Timeout() bool

Timeout indicates if this error is the result of a timeout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL