Documentation
¶
Index ¶
- func Annotate(err error, debugMsg string, opts ...Option) error
- func Define(code string, def Definition) error
- func New(debugMsg string, opts ...Option) error
- func RegisterContextExtractor(f func(context.Context) map[string]any)
- func RegisterDefinition(defErr error, def Definition)
- func ToGRPCStatus(err error) *status.Status
- func Wrap(err error, opts ...Option) error
- func WrapMsg(err error, debugMsg string, opts ...Option) error
- func Wrapf(err error, format string, args ...any) error
- type Definition
- type E
- func (e *E) Code() string
- func (e *E) DebugMessage() string
- func (e *E) Error() string
- func (e *E) GRPCCode() (codes.Code, bool)
- func (e *E) HTTPStatus() (int, bool)
- func (e *E) LogValue() slog.Value
- func (e *E) Metadata() map[string]any
- func (e *E) PCs() []uintptr
- func (e *E) PublicMessage() string
- func (e *E) Unwrap() error
- type Option
- type Problem
- type StackFrame
- type StackOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotate ¶
Annotate は新たなスタックを取得せず、文脈用の debug メッセージやメタデータのみを付与します。 cause や定義済みエラー由来の既定値は保持され、スタックは取得しません。
func Define ¶
func Define(code string, def Definition) error
Define は errors.New(code) でエラーを作成し、その定義情報を登録します(def.Code が空なら code を充当)。
func RegisterContextExtractor ¶
RegisterContextExtractor はカスタムのコンテキスト抽出器を追加します。
func RegisterDefinition ¶
func RegisterDefinition(defErr error, def Definition)
RegisterDefinition は定義済みエラーとその定義情報を関連付けます。
func ToGRPCStatus ¶
ToGRPCStatus は errorsx のメタデータから *status.Status を生成します。 Definition 由来の既定も考慮し、必要に応じて ErrorInfo(Reason=code と一部メタ)を付与します。
func Wrap ¶
Wrap は既存のエラーを包み、メタデータ等を付与します。 cause がすでにスタックを保持している場合(pc が非 nil の *E)、それを再利用し、未保持なら一度だけ取得します。
Types ¶
type E ¶
type E struct {
// contains filtered or unexported fields
}
E はこのパッケージの中核となるエラー型です。 Unwrap を通じて標準の errors.Is/As と互換性があります。 スタック(PC 群)は生成時(New/Wrap)の一度だけ取得し、整形は必要時に遅延して行います。 表示やレンダリングの責務は外部に委ね、公開 API は最小限に保ちます。
func (*E) DebugMessage ¶
DebugMessage は開発者向けメッセージ(当該フレームでの値)を返します。
func (*E) HTTPStatus ¶
HTTPStatus は HTTP ステータスを返します(未設定の場合は false)。
type Option ¶
type Option func(*E)
Option は生成時に E を設定するための関数オプションです。
func WithGrpcStatus ¶
func WithHTTPStatus ¶
func WithMetadata ¶
func WithPublicMessage ¶
type Problem ¶
type Problem struct {
Type string `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Status int `json:"status,omitempty"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Code string `json:"code,omitempty"`
Extensions map[string]any `json:"extensions,omitempty"`
}
Problem は RFC7807 の最小表現です。 拡張メンバーは簡易運用のため Extensions にネストします(トップレベル合成は行いません)。
func ToHTTPProblem ¶
ToHTTPProblem はエラーを Problem 形式に変換します(Definition の既定値も反映)。
type StackFrame ¶
StackFrame は遅延解決後の 1 フレームを表します。
func ResolveFrames ¶
func ResolveFrames(pcs []uintptr, opts ...StackOption) []StackFrame
ResolveFrames は PC 群をフレームに解決し、必要に応じてフレームフィルタを適用します。
type StackOption ¶
type StackOption func(*stackConfig)
func WithStackFilter ¶
func WithStackFilter(f func(functionName, filePath string) bool) StackOption
WithStackFilter はカスタムのフレームフィルタを設定します。true を返すとフレームを保持します。