-
Notifications
You must be signed in to change notification settings - Fork 130
/
errors.go
61 lines (47 loc) 路 1.48 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package graph
import (
"fmt"
"github.com/Masterminds/semver/v3"
)
func ErrNotInstalled(name string) error {
err := NotInstalledError(name)
return &err
}
// NotInstalledError indicates that a package is missing
type NotInstalledError string
func (err *NotInstalledError) Error() string {
return fmt.Sprintf("%v not installed", string(*err))
}
func ErrConstraint(name string, version *semver.Version, constraint *semver.Constraints, cause error) error {
return &ConstraintError{Name: name, Version: version, Constraint: constraint, cause: cause}
}
// ConstraintError indicates that a constraint has been violated
type ConstraintError struct {
Name string
Version *semver.Version
Constraint *semver.Constraints
cause error
}
func (err *ConstraintError) Error() string {
return fmt.Sprintf("constraint %v violated: %v", err.Constraint, err.cause)
}
func ErrDependency(name, dep string, cause error) error {
return &DependencyError{Name: name, Dependency: dep, cause: cause}
}
// DependencyError idicates that a dependency is not met
type DependencyError struct {
Name, Dependency string
cause error
}
func (err *DependencyError) Error() string {
return fmt.Sprintf("unmet dependency %v -> %v: %v", err.Name, err.Dependency, err.cause)
}
func (err *DependencyError) Is(other error) bool {
_, ok := other.(*DependencyError)
return ok
}
func (err *DependencyError) Unwrap() error {
return err.cause
}
var _ error = &ConstraintError{}
var _ error = &DependencyError{}