errdetails

package
v0.0.0-...-aaf5e87 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNoopSlogLogger

func NewNoopSlogLogger() *slog.Logger

NewNoopSlogLogger returns a *slog.Logger that discards all log output.

Types

type Code

type Code uint32

A Code is an unsigned 32-bit error code as defined by the gRPC spec. Only values 0 through 16 (OK through Unauthenticated) are valid. Use Code.Valid to check whether a Code is within the defined range.

const (
	// OK represents a successful status. It is NOT a valid error code and
	// must not be used with [apperr.AppError]. It is exported only for
	// completeness with the gRPC code enum.
	OK                 Code = 0
	Canceled           Code = 1
	Unknown            Code = 2
	InvalidArgument    Code = 3
	DeadlineExceeded   Code = 4
	NotFound           Code = 5
	AlreadyExists      Code = 6
	PermissionDenied   Code = 7
	ResourceExhausted  Code = 8
	FailedPrecondition Code = 9
	Aborted            Code = 10
	OutOfRange         Code = 11
	Unimplemented      Code = 12
	Internal           Code = 13
	Unavailable        Code = 14
	DataLoss           Code = 15
	Unauthenticated    Code = 16
)

func (Code) MarshalJSON

func (c Code) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It encodes Code as a SCREAMING_SNAKE_CASE JSON string (e.g. "NOT_FOUND"), matching the canonical google.rpc.Code proto enum names.

func (Code) MarshalText

func (c Code) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Code) String

func (c Code) String() string

func (*Code) UnmarshalJSON

func (c *Code) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It accepts the SCREAMING_SNAKE_CASE string form (e.g. "NOT_FOUND").

func (*Code) UnmarshalText

func (c *Code) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Code) Valid

func (c Code) Valid() bool

Valid reports whether c is a defined gRPC status code (0–16 inclusive).

type DebugInfo

type DebugInfo struct {
	StackEntries []string `json:"stackEntries,omitempty"`
	Detail       string   `json:"detail"`
}

DebugInfo describes additional debugging information provided by the server, such as stack traces. This detail type should only be used during development or when the information is safe to expose; it must NOT be returned to untrusted clients in production.

type ErrorInfo

type ErrorInfo struct {
	Reason   string            `json:"reason"`
	Domain   string            `json:"domain"`
	Metadata map[string]string `json:"metadata"`
}

ErrorInfo describes the cause of the error with structured details.

type HelpLink struct {
	URL         string `json:"url"`
	Description string `json:"description"`
}

HelpLink is a URL pointing to documentation or an out-of-band action.

type LocalizationProvider

type LocalizationProvider interface {
	Localize(messageID string, languages []language.Tag) (msg string, tag language.Tag, notFound bool, err error)
	LocalizeAny(v any, languages []language.Tag) (msg string, tag language.Tag, notFound bool, err error)
}

LocalizationProvider is implemented by localization adapters (e.g. x/i18n) to translate message IDs into localized strings.

type LocalizedMessage

type LocalizedMessage struct {
	Locale language.Tag `json:"locale"`
	Text   string       `json:"text"`
}

LocalizedMessage is a translated user-facing message.

type PreconditionViolation

type PreconditionViolation struct {
	Type        string `json:"type"`
	Subject     string `json:"subject"`
	Description string `json:"description"`
}

PreconditionViolation describes a single precondition failure.

type QuotaViolation

type QuotaViolation struct {
	Subject     string `json:"subject"`
	Description string `json:"description"`
}

QuotaViolation describes a single quota failure.

type RawFieldViolation

type RawFieldViolation struct {
	Field          string  `json:"-"`
	Description    *string `json:"-"`
	DescriptionID  *string `json:"-"`
	DescriptionAny any     `json:"-"`
}

RawFieldViolation holds the unresolved field violation input.

type RawLocalized

type RawLocalized struct {
	TextID *string `json:"-"`
	Any    any     `json:"-"`
}

RawLocalized holds the unresolved localization input. Either TextID or Any is set by the caller; the resolve step translates them into a LocalizedMessage.

type RequestInfo

type RequestInfo struct {
	RequestID   string `json:"requestId"`
	ServingData string `json:"servingData"`
}

RequestInfo contains metadata about the request.

type ResolvedError

type ResolvedError struct {
	Code    Code   `json:"code"`
	Message string `json:"message"`
	// Headers holds HTTP headers that should be sent alongside the error
	// response. They are excluded from JSON serialization and are instead
	// applied directly by the transport-layer interceptor or middleware
	// if applicable for the framework in use.
	Headers                http.Header               `json:"-"`
	Localized              *LocalizedMessage         `json:"localized,omitempty"`
	RequestInfo            *RequestInfo              `json:"requestInfo,omitempty"`
	ResourceInfo           *ResourceInfo             `json:"resourceInfo,omitempty"`
	ErrorInfo              *ErrorInfo                `json:"errorInfo,omitempty"`
	HelpLinks              []*HelpLink               `json:"helpLinks,omitempty"`
	FieldViolations        []*ResolvedFieldViolation `json:"fieldViolations,omitempty"`
	PreconditionViolations []*PreconditionViolation  `json:"preconditionViolations,omitempty"`
	QuotaViolations        []*QuotaViolation         `json:"quotaViolations,omitempty"`
	RetryInfo              *RetryInfo                `json:"retryInfo,omitempty"`
	DebugInfo              *DebugInfo                `json:"debugInfo,omitempty"`
}

ResolvedError is the fully resolved form of an AppError, ready for conversion to a framework-specific error type by an x/ converter.

type ResolvedFieldViolation

type ResolvedFieldViolation struct {
	Locale      *language.Tag `json:"locale,omitempty"`
	Field       string        `json:"field"`
	Description string        `json:"description"`
}

ResolvedFieldViolation is a field violation with its description resolved (possibly translated).

type ResourceInfo

type ResourceInfo struct {
	Type        string `json:"type"`
	Name        string `json:"name"`
	Owner       string `json:"owner"`
	Description string `json:"description"`
}

ResourceInfo describes the resource being accessed.

type RetryInfo

type RetryInfo struct {
	Delay int `json:"delay"`
}

RetryInfo advises the client on when to retry. The Delay field is expressed in milliseconds.

type UnresolvedError

type UnresolvedError struct {
	Code                   Code
	Message                string
	Headers                http.Header
	RawLocalized           *RawLocalized
	Localized              *LocalizedMessage
	RequestInfo            *RequestInfo
	ResourceInfo           *ResourceInfo
	ErrorInfo              *ErrorInfo
	HelpLinks              []*HelpLink
	RawFieldViolations     []*RawFieldViolation
	FieldViolations        []*ResolvedFieldViolation
	PreconditionViolations []*PreconditionViolation
	QuotaViolations        []*QuotaViolation
	RetryInfo              *RetryInfo
	DebugInfo              *DebugInfo
}

UnresolvedError is the accumulation target used during option application and localization. It carries both the raw intermediate fields (RawLocalized, RawFieldViolations) and the fields that are already resolved at apply time. After resolution the resolve package projects it into a ResolvedError, which contains only the final consumer-facing fields.

Jump to

Keyboard shortcuts

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