2024-08-22 17:26:53 +07:00
|
|
|
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
|
2024-08-28 11:01:20 +07:00
|
|
|
// LogRecord returns log records to be consumed by logger.
|
|
|
|
LogRecord() slog.Record
|
2024-08-22 17:26:53 +07:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
2024-08-26 16:24:41 +07:00
|
|
|
// If unset, the ID will be automatically generated depending
|
|
|
|
// on the backend logging and notification.
|
|
|
|
ID(s string, args ...any) Error
|
2024-08-22 17:26:53 +07:00
|
|
|
GetID() string
|
|
|
|
|
2024-08-26 16:24:41 +07:00
|
|
|
// Join appends given errors to this zerr.Error.
|
|
|
|
//
|
|
|
|
// Join discards nil errors.
|
|
|
|
//
|
|
|
|
// When searching for Code, Message, PublicMessage, etc,
|
|
|
|
// only the first error containing valid values will be used.
|
|
|
|
//
|
|
|
|
// The searching method is depth-first.
|
|
|
|
//
|
|
|
|
// It's undefined behavior to call Join when another thread calls
|
|
|
|
// .Sequence().Iter() on this error.
|
|
|
|
Join(errs ...error) Error
|
|
|
|
|
2024-08-26 19:42:19 +07:00
|
|
|
// Log logs the error to stderr.
|
|
|
|
//
|
|
|
|
// Format will be pretty if current runtime is run in interactive
|
|
|
|
// environment (TTY is detected), e.g. running inside terminal via `go run` command.
|
|
|
|
//
|
|
|
|
// Format will be JSON if current runtime does not have TTY, e.g.
|
|
|
|
// running inside Docker container, Kubernetes pod, or any non-interactive environment
|
|
|
|
// like VSCode debugger.
|
2024-08-22 17:26:53 +07:00
|
|
|
Log(ctx context.Context) Error
|
2024-08-26 19:42:19 +07:00
|
|
|
|
|
|
|
// Notify sends the error to the zen Server
|
|
|
|
// which will then handle the error and create reports.
|
2024-08-22 17:26:53 +07:00
|
|
|
Notify(ctx context.Context, opts ...zoptions.NotifyOption) Error
|
|
|
|
|
|
|
|
// Sequence returns the state of the error sequence.
|
2024-08-27 17:08:52 +07:00
|
|
|
//
|
|
|
|
// Sequence must not be nil.
|
|
|
|
Sequence() Sequence
|
2024-08-23 18:41:19 +07:00
|
|
|
|
|
|
|
// IsMulti returns true if the error is a multiple error.
|
|
|
|
IsMulti() bool
|
|
|
|
|
|
|
|
// Resolve returns error (self) if all the errors
|
2024-08-26 16:24:41 +07:00
|
|
|
// are valid (not nil) and Error contains at least one error
|
|
|
|
// wrapped.
|
2024-08-23 18:41:19 +07:00
|
|
|
Resolve() error
|
2024-08-22 17:26:53 +07:00
|
|
|
}
|