Documentation
¶
Index ¶
- Constants
- func AppendDetailsMetadata(err error, key MetadataKey, value string) error
- func CombineMetadata(withMetadata WithMetadata, metadata map[string]string) map[string]string
- func DebugAssertNotNilf(obj any, format string, args ...any)
- func DebugAssertf(condition func() bool, format string, args ...any)
- func ForReason(reason v1.ErrorReason, metadata map[string]string) *errdetails.ErrorInfo
- func GetDetails[T protoiface.MessageV1](err error) (T, bool)
- func IsInTests() bool
- func MustBugf(format string, args ...any) error
- func MustPanicf(format string, args ...any)
- func MustSafecast[To, From safecast.Number](from From) To
- func RequireReason(t testing.TB, reason v1.ErrorReason, err error, expectedMetadataKeys ...string)
- func SetFinalizerForDebugging[T any](obj any, finalizer func(obj T))
- func WithAdditionalDetails(err error, key MetadataKey, value string) bool
- func WithCodeAndDetails(err error, code codes.Code, details ...protoiface.MessageV1) *status.Status
- func WithCodeAndDetailsAsError(err error, code codes.Code, details ...protoiface.MessageV1) error
- func WithCodeAndReason(err error, code codes.Code, reason v1.ErrorReason) error
- func WithReplacedDetails[T protoiface.MessageV1](err error, toReplace T) error
- type ErrorBuilder
- func (eb *ErrorBuilder) Component(component string) *ErrorBuilder
- func (eb *ErrorBuilder) Error() TerminationError
- func (eb *ErrorBuilder) ExitCode(exitCode int) *ErrorBuilder
- func (eb *ErrorBuilder) Metadata(key, value string) *ErrorBuilder
- func (eb *ErrorBuilder) Timestamp(timestamp time.Time) *ErrorBuilder
- type HasMetadata
- type MetadataKey
- type SourcePosition
- type SupportsAdditionalMetadata
- type TerminationError
- type WithAdditionalDetailsError
- type WithMetadata
- type WithSourceError
Constants ¶
const DebugAssertionsEnabled = false
const Domain = "authzed.com"
Domain is the domain used for all errors.
Variables ¶
This section is empty.
Functions ¶
func AppendDetailsMetadata ¶ added in v1.35.3
func AppendDetailsMetadata(err error, key MetadataKey, value string) error
AppendDetailsMetadata appends the key-value pair to the error details metadata. If the error is nil or is not a status error, it is returned as is.
func CombineMetadata ¶ added in v1.16.2
func CombineMetadata(withMetadata WithMetadata, metadata map[string]string) map[string]string
CombineMetadata combines the metadata found on an existing error with that given.
func DebugAssertNotNilf ¶ added in v1.46.1
DebugAssertNotNilf is a no-op in non-CI builds
func DebugAssertf ¶ added in v1.46.1
DebugAssertf is a no-op in non-CI builds
func ForReason ¶
func ForReason(reason v1.ErrorReason, metadata map[string]string) *errdetails.ErrorInfo
ForReason returns an ErrorInfo block for a specific error reason as defined in the V1 API.
func GetDetails ¶ added in v1.35.3
func GetDetails[T protoiface.MessageV1](err error) (T, bool)
GetDetails returns the details of the error if they are of the provided type, if any.
func IsInTests ¶ added in v1.22.2
func IsInTests() bool
IsInTests returns true if go test is running Based on: https://stackoverflow.com/a/58945030
func MustBugf ¶ added in v1.16.0
MustBugf returns an error representing a bug in the system. Will panic if run under testing.
func MustPanicf ¶ added in v1.46.1
MustPanicf is a special function for panicing when necessary to violate the linter.
func MustSafecast ¶ added in v1.52.0
MustSafecast converts a value from one numeric type to another using safecast. If the conversion fails (value out of range), it panics in tests and returns the zero value in production. This should only be used where the value is expected to always be convertible (e.g., converting from a statically defined value or a value known to be non-negative).
func RequireReason ¶
RequireReason asserts that an error is a gRPC error and returns the expected reason in the ErrorInfo. TODO(jschorr): Move into grpcutil.
func SetFinalizerForDebugging ¶ added in v1.36.0
SetFinalizerForDebugging is a no-op in non-CI builds
func WithAdditionalDetails ¶ added in v1.34.0
func WithAdditionalDetails(err error, key MetadataKey, value string) bool
WithAdditionalDetails adds an additional details field to the error if it is possible.
func WithCodeAndDetails ¶
WithCodeAndDetails returns a gRPC status message containing the error's message, the given status code and any supplied details.
func WithCodeAndDetailsAsError ¶ added in v1.22.0
WithCodeAndDetailsAsError returns an error containing the error's message, the given status code and any supplied details.
func WithCodeAndReason ¶
WithCodeAndReason returns a new error which wraps the existing error with a gRPC code and a reason block.
func WithReplacedDetails ¶ added in v1.35.3
func WithReplacedDetails[T protoiface.MessageV1](err error, toReplace T) error
WithReplacedDetails replaces the details of the error with the provided details. If the error is nil or is not a status error, it is returned as is. If the error does not have the details to replace, the provided details are appended.
Types ¶
type ErrorBuilder ¶ added in v1.22.0
type ErrorBuilder struct {
// contains filtered or unexported fields
}
ErrorBuilder is a fluent-style builder for TerminationError
func NewTerminationErrorBuilder ¶ added in v1.22.0
func NewTerminationErrorBuilder(err error) *ErrorBuilder
NewTerminationErrorBuilder returns a new ErrorBuilder for a termination.TerminationError.
func (*ErrorBuilder) Component ¶ added in v1.22.0
func (eb *ErrorBuilder) Component(component string) *ErrorBuilder
Component specifies the component in SpiceDB that
func (*ErrorBuilder) Error ¶ added in v1.22.0
func (eb *ErrorBuilder) Error() TerminationError
TerminationError returns the built termination TerminationError
func (*ErrorBuilder) ExitCode ¶ added in v1.22.0
func (eb *ErrorBuilder) ExitCode(exitCode int) *ErrorBuilder
ExitCode defines the ExitCode to be used upon process termination. Defaults to 1 if not specified.
func (*ErrorBuilder) Metadata ¶ added in v1.22.0
func (eb *ErrorBuilder) Metadata(key, value string) *ErrorBuilder
Metadata adds a new key-value pair of metadata to the termination TerminationError being built
func (*ErrorBuilder) Timestamp ¶ added in v1.22.0
func (eb *ErrorBuilder) Timestamp(timestamp time.Time) *ErrorBuilder
Timestamp defines the time of the error. Defaults to time.Now().UTC() if not specified.
type HasMetadata ¶
type HasMetadata interface {
// DetailsMetadata returns the metadata for details for this error.
DetailsMetadata() map[string]string
}
HasMetadata indicates that the error has metadata defined.
type MetadataKey ¶ added in v1.35.3
type MetadataKey string
MetadataKey is the type used to represent the keys of the metadata map in the error details.
const DebugTraceErrorDetailsKey MetadataKey = "debug_trace_proto_text"
DebugTraceErrorDetailsKey is the key used to store the debug trace in the error details. The value is expected to be a string containing the proto text of a DebugInformation message.
type SourcePosition ¶
type SourcePosition struct {
// LineNumber is the 1-indexed line number in the input source.
LineNumber int
// ColumnPosition is the 1-indexed column position in the input source.
ColumnPosition int
}
SourcePosition is a position in the input source.
type SupportsAdditionalMetadata ¶ added in v1.34.0
type SupportsAdditionalMetadata interface {
WithAdditionalDetails(key MetadataKey, value string)
}
type TerminationError ¶ added in v1.22.0
type TerminationError struct {
Component string `json:"component"`
Timestamp time.Time `json:"timestamp"`
ErrorString string `json:"error"`
Metadata map[string]string `json:"metadata"`
// contains filtered or unexported fields
}
TerminationError represents an error that captures contextual information to make available on process termination. The error will be marshalled as JSON and serialized into a file-path specified via CLI arguments
func (TerminationError) ExitCode ¶ added in v1.22.0
func (e TerminationError) ExitCode() int
ExitCode returns the exit code to be returned on process termination
type WithAdditionalDetailsError ¶ added in v1.39.0
type WithAdditionalDetailsError struct {
// AdditionalDetails is a map of additional details for the error.
AdditionalDetails map[string]string
// contains filtered or unexported fields
}
WithAdditionalDetailsError is an error that includes additional details.
func NewWithAdditionalDetailsError ¶ added in v1.39.0
func NewWithAdditionalDetailsError(err error) *WithAdditionalDetailsError
func (*WithAdditionalDetailsError) AddToDetails ¶ added in v1.39.0
func (err *WithAdditionalDetailsError) AddToDetails(details map[string]string) map[string]string
func (*WithAdditionalDetailsError) Unwrap ¶ added in v1.39.0
func (err *WithAdditionalDetailsError) Unwrap() error
Unwrap returns the inner, wrapped error.
func (*WithAdditionalDetailsError) WithAdditionalDetails ¶ added in v1.39.0
func (err *WithAdditionalDetailsError) WithAdditionalDetails(key string, value string)
type WithMetadata ¶ added in v1.16.2
type WithSourceError ¶ added in v1.39.0
type WithSourceError struct {
// SourceCodeString is the input source code string for the error.
SourceCodeString string
// LineNumber is the (1-indexed) line number of the error, or 0 if unknown.
LineNumber uint64
// ColumnPosition is the (1-indexed) column position of the error, or 0 if
// unknown.
ColumnPosition uint64
// contains filtered or unexported fields
}
WithSourceError is an error that includes the source text and position information.
func AsWithSourceError ¶ added in v1.39.0
func AsWithSourceError(err error) (*WithSourceError, bool)
AsWithSourceError returns the error as an WithSourceError, if applicable.
func NewWithSourceError ¶ added in v1.39.0
func NewWithSourceError(err error, sourceCodeString string, oneIndexedLineNumber uint64, oneIndexedColumnPosition uint64) *WithSourceError
NewWithSourceError creates and returns a new WithSourceError.
func (*WithSourceError) Unwrap ¶ added in v1.39.0
func (err *WithSourceError) Unwrap() error
Unwrap returns the inner, wrapped error.