go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

error.go (829B)


      1 package db
      2 
      3 import (
      4 	"errors"
      5 	"fmt"
      6 	"strings"
      7 )
      8 
      9 const (
     10 	notFoundPrefix = "key not found: "
     11 )
     12 
     13 var (
     14 	ErrTxExist  = errors.New("tx already exists")
     15 	ErrNoTx     = errors.New("tx does not exist")
     16 	ErrSingleTx = errors.New("not a multi-instruction tx")
     17 )
     18 
     19 // ErrNotFound is returned with a key was successfully queried, but did not match a stored key.
     20 type ErrNotFound struct {
     21 	k []byte
     22 }
     23 
     24 // NewErrNotFound creates a new ErrNotFound with the given storage key.
     25 func NewErrNotFound(k []byte) error {
     26 	return ErrNotFound{k}
     27 }
     28 
     29 // Error implements Error.
     30 func (e ErrNotFound) Error() string {
     31 	return fmt.Sprintf("%s%x", notFoundPrefix, e.k)
     32 }
     33 
     34 func (e ErrNotFound) Is(err error) bool {
     35 	return strings.Contains(err.Error(), notFoundPrefix)
     36 }
     37 
     38 func IsNotFound(err error) bool {
     39 	target := ErrNotFound{}
     40 	return target.Is(err)
     41 }