Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
Go
at icy/nmoxmq
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126package errors
import ( "encoding/json" "fmt")
type XrpcError struct { Tag string `json:"error"` Message string `json:"message"`}
func (x XrpcError) Error() string { if x.Message != "" { return fmt.Sprintf("%s: %s", x.Tag, x.Message) } return x.Tag}
func NewXrpcError(opts ...ErrOpt) XrpcError { x := XrpcError{} for _, o := range opts { o(&x) }
return x}
type ErrOpt = func(xerr *XrpcError)
func WithTag(tag string) ErrOpt { return func(xerr *XrpcError) { xerr.Tag = tag }}
func WithMessage[S ~string](s S) ErrOpt { return func(xerr *XrpcError) { xerr.Message = string(s) }}
func WithError(e error) ErrOpt { return func(xerr *XrpcError) { xerr.Message = e.Error() }}
var MissingActorDidError = NewXrpcError( WithTag("MissingActorDid"), WithMessage("actor DID not supplied"),)
var OwnerNotFoundError = NewXrpcError( WithTag("OwnerNotFound"), WithMessage("owner not set for this service"),)
var RepoNotFoundError = NewXrpcError( WithTag("RepoNotFound"), WithMessage("failed to access repository"),)
var RefNotFoundError = NewXrpcError( WithTag("RefNotFound"), WithMessage("failed to access ref"),)
var AuthError = func(err error) XrpcError { return NewXrpcError( WithTag("Auth"), WithError(fmt.Errorf("signature verification failed: %w", err)), )}
var InvalidRepoError = func(r string) XrpcError { return NewXrpcError( WithTag("InvalidRepo"), WithError(fmt.Errorf("supplied at-uri is not a repo: %s", r)), )}
var GitError = func(e error) XrpcError { return NewXrpcError( WithTag("Git"), WithError(fmt.Errorf("git error: %w", e)), )}
var AccessControlError = func(d string) XrpcError { return NewXrpcError( WithTag("AccessControl"), WithError(fmt.Errorf("DID does not have sufficent access permissions for this operation: %s", d)), )}
var RepoExistsError = func(r string) XrpcError { return NewXrpcError( WithTag("RepoExists"), WithError(fmt.Errorf("repo already exists: %s", r)), )}
var RecordExistsError = func(r string) XrpcError { return NewXrpcError( WithTag("RecordExists"), WithError(fmt.Errorf("repo already exists: %s", r)), )}
func GenericError(err error) XrpcError { return NewXrpcError( WithTag("Generic"), WithError(err), )}
func Unmarshal(errStr string) (XrpcError, error) { var xerr XrpcError err := json.Unmarshal([]byte(errStr), &xerr) if err != nil { return XrpcError{}, fmt.Errorf("failed to unmarshal XrpcError: %w", err) } return xerr, nil}