-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
errors.go
39 lines (31 loc) · 1.03 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
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
// Copyright 2021 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
// Package errors contains reusable error-related code for the storage layer.
package errors
import (
"fmt"
"github.com/open-policy-agent/opa/storage"
)
const ArrayIndexTypeMsg = "array index must be integer"
const DoesNotExistMsg = "document does not exist"
const OutOfRangeMsg = "array index out of range"
func NewNotFoundError(path storage.Path) *storage.Error {
return NewNotFoundErrorWithHint(path, DoesNotExistMsg)
}
func NewNotFoundErrorWithHint(path storage.Path, hint string) *storage.Error {
return NewNotFoundErrorf("%v: %v", path.String(), hint)
}
func NewNotFoundErrorf(f string, a ...interface{}) *storage.Error {
msg := fmt.Sprintf(f, a...)
return &storage.Error{
Code: storage.NotFoundErr,
Message: msg,
}
}
func NewWriteConflictError(p storage.Path) *storage.Error {
return &storage.Error{
Code: storage.WriteConflictErr,
Message: p.String(),
}
}