forked from gomods/athens
/
not_found_err.go
53 lines (43 loc) · 1.2 KB
/
not_found_err.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
package storage
import (
"fmt"
)
// ErrNotFound is an error implementation that indicates a module
// doesn't exist
type ErrNotFound struct {
Module string
}
func (n ErrNotFound) Error() string {
return fmt.Sprintf("module %s not found", n.Module)
}
// ErrVersionNotFound is an error implementation that indicates a module
// at a specific version doesn't exist
type ErrVersionNotFound struct {
Module string
Version string
}
func (e ErrVersionNotFound) Error() string {
return fmt.Sprintf("module %s@%s not found", e.Module, e.Version)
}
// IsNotFoundError returns true if err is an ErrNotFound
func IsNotFoundError(err error) bool {
if _, ok := err.(ErrNotFound); ok {
return ok
}
_, ok := err.(ErrVersionNotFound)
return ok
}
// ErrVersionAlreadyExists is an error implementation that indicates that a
// module@version already exists
type ErrVersionAlreadyExists struct {
Module string
Version string
}
func (e ErrVersionAlreadyExists) Error() string {
return fmt.Sprintf("%s@%s already exists", e.Module, e.Version)
}
// IsVersionAlreadyExistsErr returns true if err is an ErrVersionAlreadyExists
func IsVersionAlreadyExistsErr(err error) bool {
_, ok := err.(ErrVersionAlreadyExists)
return ok
}