go-vise

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

error.go (659B)


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