-
Notifications
You must be signed in to change notification settings - Fork 110
/
errors.go
42 lines (33 loc) · 1.6 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
40
41
42
package utils
import (
"github.com/pkg/errors"
"go.viam.com/rdk/resource"
)
// NewResourceNotFoundError is used when a resource is not found.
func NewResourceNotFoundError(name resource.Name) error {
return errors.Errorf("resource %q not found", name)
}
// NewResourceNotAvailableError is used when a resource is not available because of some error.
func NewResourceNotAvailableError(name resource.Name, err error) error {
return errors.Wrapf(err, "resource %q not available", name)
}
// NewRemoteResourceClashError is used when you are more than one resource with the same name exist.
func NewRemoteResourceClashError(name string) error {
return errors.Errorf("more that one remote resources with name %q exists", name)
}
// DependencyNotFoundError is used when a resource is not found in a dependencies.
func DependencyNotFoundError(name string) error {
return errors.Errorf("%q missing from dependencies", name)
}
// DependencyTypeError is used when a resource doesn't implement the expected interface.
func DependencyTypeError(name, expected, actual interface{}) error {
return errors.Errorf("dependency %q should an implementation of %T but it was a %T", name, expected, actual)
}
// NewUnexpectedTypeError is used when there is a type mismatch.
func NewUnexpectedTypeError(expected, actual interface{}) error {
return errors.Errorf("expected %T but got %T", expected, actual)
}
// NewUnimplementedInterfaceError is used when there is a failed interface check.
func NewUnimplementedInterfaceError(expected, actual interface{}) error {
return errors.Errorf("expected implementation of %T but got %T", expected, actual)
}