Documentation
¶
Overview ¶
Package errx 定义 L0 错误分类和可序列化错误契约。
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
Kind ErrorKind `json:"kind"`
Code string `json:"code,omitempty"`
Severity Severity `json:"severity,omitempty"`
Op string `json:"op,omitempty"`
Message string `json:"message"`
Cause error `json:"-"`
Retryable bool `json:"retryable"`
}
Error is the common kernel error type for infrastructure contracts.
func NewError ¶
NewError creates an Error without a wrapped cause.
Example ¶
package main
import (
"github.com/ZoneCNH/kernel/errx"
)
func main() {
_ = errx.NewError(errx.ErrorKindValidation, "user.Create", "invalid name").
WithCode("INVALID_NAME").
WithSeverity(errx.SeverityWarning)
}
Output:
func (*Error) WithCode ¶
WithCode sets a stable machine-readable code and returns the same pointer.
Use only during Error construction; do not call on errors already shared or returned.
func (*Error) WithRetryable ¶
WithRetryable sets whether the operation may be retried by an upper layer. It mutates the receiver and returns the same pointer for construction-time annotation.
Use only during Error construction; do not call on errors already shared or returned.
func (*Error) WithSeverity ¶
WithSeverity sets operator-facing impact and returns the same pointer.
Use only during Error construction; do not call on errors already shared or returned.
type ErrorKind ¶
type ErrorKind string
ErrorKind classifies infrastructure-level failures without binding to a specific driver or business domain.
const ( ErrorKindConfig ErrorKind = "config" ErrorKindValidation ErrorKind = "validation" ErrorKindConnection ErrorKind = "connection" ErrorKindTimeout ErrorKind = "timeout" ErrorKindAuth ErrorKind = "auth" ErrorKindConflict ErrorKind = "conflict" ErrorKindRateLimit ErrorKind = "rate_limit" ErrorKindCanceled ErrorKind = "canceled" ErrorKindNotFound ErrorKind = "not_found" ErrorKindAlreadyExist ErrorKind = "already_exists" ErrorKindInternal ErrorKind = "internal" )