zen/core/zerr/error.go
2024-08-22 17:26:53 +07:00

65 lines
1.6 KiB
Go

package zerr
import (
"context"
"log/slog"
"time"
"connectrpc.com/connect"
"gitlab.bareksa.com/backend/zen/core/zoptions"
)
type Error interface {
error
// LogValue returns log fields to be consumed by logger.
LogValue() slog.Value
// Code sets error code.
Code(code connect.Code) Error
GetCode() connect.Code
// Message sets error message. It uses fmt.Sprintf to format the message.
Message(msg string, args ...any) Error
GetMessage() string
PublicMessage(msg string, args ...any) Error
GetPublicMessage() string
Caller(pc uintptr) Error
GetCaller() uintptr
// Details sets error details. It's a key-value pair where the odd index is the key and the even index is the value.
//
// Invalid key-value pair number and format will cause the misplaced value to be paired up with "!BADKEY".
//
// Example:
//
// err.Details(
// "key1", 12345,
// "key2", float64(12345.67),
// )
Details(fields ...any) Error
GetDetails() []any
// Time sets the error time.
//
// Time is already set to current when the error is created or wrapped,
// so this method is only useful when you want to set a different time.
Time(t time.Time) Error
GetTime() time.Time
// ID sets the error ID.
//
// ID is used to identify the error. Used by Zen to consider if an error is the same as another.
//
// Current implementation
ID(msg string, args ...any) Error
GetID() string
Log(ctx context.Context) Error
Notify(ctx context.Context, opts ...zoptions.NotifyOption) Error
// Sequence returns the state of the error sequence.
Sequence() *Sequence
}