1
// Copyright 2019 Miguel Angel Rivera Notararigo. All rights reserved.
2
// This source code was released under the MIT license.
3

4
package sdb
5

6
import (
7
	"fmt"
8
	"strings"
9

10
	"github.com/dgraph-io/badger/v2"
11
)
12

13
var (
14
	ErrKeyNotFound = badgerError(badger.ErrKeyNotFound)
15
)
16

17
// IsBadgerError returns true if the given error is from Badger.
18 1
func IsBadgerError(err error) bool {
19 1
	return errorContains(err, "badger: ")
20
}
21

22
// IsBleveError returns true if the given error is from Bleve.
23 1
func IsBleveError(err error) bool {
24 1
	return errorContains(err, "bleve: ")
25
}
26

27 1
func badgerError(err error) error {
28 1
	return fmt.Errorf("badger: %w", err)
29
}
30

31 1
func bleveError(err error) error {
32 1
	return fmt.Errorf("bleve: %w", err)
33
}
34

35 1
func errorContains(err error, s string) bool {
36 1
	if err == nil {
37 1
		return false
38
	}
39

40 1
	return strings.Contains(err.Error(), s)
41
}

Read our documentation on viewing source code .

Loading