Documentation
¶
Index ¶
- func NewNoopSlogLogger() *slog.Logger
- type Code
- type DebugInfo
- type ErrorInfo
- type HelpLink
- type LocalizationProvider
- type LocalizedMessage
- type PreconditionViolation
- type QuotaViolation
- type RawFieldViolation
- type RawLocalized
- type RequestInfo
- type ResolvedError
- type ResolvedFieldViolation
- type ResourceInfo
- type RetryInfo
- type UnresolvedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNoopSlogLogger ¶
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 DataLoss Code = 15 Unauthenticated Code = 16 )
func (Code) MarshalJSON ¶
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 ¶
MarshalText implements encoding.TextMarshaler.
func (*Code) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It accepts the SCREAMING_SNAKE_CASE string form (e.g. "NOT_FOUND").
func (*Code) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
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 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 ¶
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 ¶
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.