-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy patherrors.go
More file actions
98 lines (78 loc) · 2.54 KB
/
errors.go
File metadata and controls
98 lines (78 loc) · 2.54 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package batches
import (
"fmt"
"strings"
"github.com/sourcegraph/src-cli/internal/batches/graphql"
)
// TODO(mrnugget): Merge these two types (give them an "errorfmt" function,
// rename "Has*" methods to "NotEmpty" or something)
// UnsupportedRepoSet provides a set to manage repositories that are on
// unsupported code hosts. This type implements error to allow it to be
// returned directly as an error value if needed.
type UnsupportedRepoSet map[*graphql.Repository]struct{}
func (e UnsupportedRepoSet) Includes(r *graphql.Repository) bool {
_, ok := e[r]
return ok
}
func (e UnsupportedRepoSet) Error() string {
repos := []string{}
typeSet := map[string]struct{}{}
for repo := range e {
repos = append(repos, repo.Name)
typeSet[repo.ExternalRepository.ServiceType] = struct{}{}
}
types := []string{}
for t := range typeSet {
types = append(types, t)
}
return fmt.Sprintf(
"found repositories on unsupported code hosts: %s\nrepositories:\n\t%s",
strings.Join(types, ", "),
strings.Join(repos, "\n\t"),
)
}
func (e UnsupportedRepoSet) Append(repo *graphql.Repository) {
e[repo] = struct{}{}
}
func (e UnsupportedRepoSet) HasUnsupported() bool {
return len(e) > 0
}
// IgnoredRepoSet provides a set to manage repositories that are on
// unsupported code hosts. This type implements error to allow it to be
// returned directly as an error value if needed.
type IgnoredRepoSet map[*graphql.Repository]struct{}
func (e IgnoredRepoSet) Includes(r *graphql.Repository) bool {
_, ok := e[r]
return ok
}
func (e IgnoredRepoSet) Error() string {
repos := []string{}
for repo := range e {
repos = append(repos, repo.Name)
}
return fmt.Sprintf(
"found repositories containing .batchignore files:\n\t%s",
strings.Join(repos, "\n\t"),
)
}
func (e IgnoredRepoSet) Append(repo *graphql.Repository) {
e[repo] = struct{}{}
}
func (e IgnoredRepoSet) HasIgnored() bool {
return len(e) > 0
}
// BatchChangesDisabledError indicates that Batch Changes is unavailable on the
// target instance, typically because the GraphQL schema does not expose the
// relevant fields when the feature is disabled.
type BatchChangesDisabledError struct {
cause error
}
func NewBatchChangesDisabledError(cause error) *BatchChangesDisabledError {
return &BatchChangesDisabledError{cause: cause}
}
func (e *BatchChangesDisabledError) Error() string {
return "Batch Changes is disabled on this Sourcegraph instance. Ask your site admin to enable Batch Changes before running 'src batch' commands."
}
func (e *BatchChangesDisabledError) Unwrap() error {
return e.cause
}