storage.go 708 Bytes
Newer Older
1 2 3 4
package storage

import (
	"errors"
5 6

	"xbus.io/go-xbus/v3/api"
7 8 9 10 11 12
)

var (
	// ErrNoSuchID is returned when a non-existing id is passed to some function
	ErrNoSuchID = errors.New("No such ID")
)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

type Datatype string

func (d Datatype) String() string {
	return string(d)
}

const (
	DatatypeEnvelope Datatype = "envelope"
)

type NoSuchIDError struct {
	datatype Datatype
	id       api.UUID
}

func (err NoSuchIDError) Unwrap() error {
	return ErrNoSuchID
}

func (err NoSuchIDError) Error() string {
	return "No such " + err.datatype.String() + ": " + err.id.String()
}

func NewNoSuchIDError(datatype Datatype, id api.UUID) *NoSuchIDError {
	return &NoSuchIDError{
		datatype: datatype,
		id:       id,
	}
}