-
Notifications
You must be signed in to change notification settings - Fork 244
/
errors.go
212 lines (173 loc) · 6.47 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright 2020-2024 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package internal
import (
"errors"
"fmt"
"strings"
)
var (
knownCompressionTypeStrings = []string{
"none",
"gzip",
"zstd",
}
)
// NewFormatNotAllowedError is a fetch error.
func NewFormatNotAllowedError(format string, allowedFormats map[string]struct{}) error {
return fmt.Errorf("format was %q but must be one of %s", format, formatsToString(allowedFormats))
}
// NewFormatCannotBeDeterminedError is a fetch error.
func NewFormatCannotBeDeterminedError(value string) error {
return fmt.Errorf("format cannot be determined from %q", value)
}
// NewCannotSpecifyGitBranchAndCommitOrTagError is a fetch error.
func NewCannotSpecifyGitBranchAndCommitOrTagError() error {
return errors.New(`must specify only one of "branch", "commit", or "tag"`)
}
// NewCannotSpecifyCommitOrTagWithRefError is a fetch error.
func NewCannotSpecifyCommitOrTagWithRefError() error {
return errors.New(`cannot specify "commit" or "tag" with "ref"`)
}
// NewDepthParseError is a fetch error.
func NewDepthParseError(s string) error {
return fmt.Errorf(`could not parse "depth" value %q`, s)
}
// NewDepthZeroError is a fetch error.
func NewDepthZeroError() error {
return errors.New(`"depth" must be >0 if specified`)
}
// NewPathUnknownGzError is a fetch error.
func NewPathUnknownGzError(path string) error {
return fmt.Errorf("path %q had .gz extension with unknown format", path)
}
// NewCompressionUnknownError is a fetch error.
func NewCompressionUnknownError(compression string) error {
return fmt.Errorf("unknown compression: %q (valid values are %q)", compression, strings.Join(knownCompressionTypeStrings, ","))
}
// NewCannotSpecifyCompressionForZipError is a fetch error.
func NewCannotSpecifyCompressionForZipError() error {
return errors.New("cannot specify compression type for zip files")
}
// NewNoPathError is a fetch error.
func NewNoPathError() error {
return errors.New("value has no path once processed")
}
// NewOptionsInvalidKeysError is a fetch error.
func NewOptionsInvalidKeysError(keys ...string) error {
if len(keys) == 1 {
return fmt.Errorf("invalid key: %q", keys[0])
}
return fmt.Errorf("invalid keys: \"%v\"", strings.Join(keys, ", "))
}
// NewOptionsInvalidValueForKeyError is a fetch error.
func NewOptionsInvalidValueForKeyError(key string, value string) error {
return fmt.Errorf("invalid value %q for key: %q", value, key)
}
// NewOptionsInvalidForFormatError is a fetch error.
func NewOptionsInvalidForFormatError(format string, inputName string, issue string) error {
return fmt.Errorf("invalid options for input %q for format %q: %s", inputName, format, issue)
}
// NewOptionsCouldNotParseStripComponentsError is a fetch error.
func NewOptionsCouldNotParseStripComponentsError(s string) error {
return fmt.Errorf("could not parse strip_components value %q", s)
}
// NewOptionsCouldNotParseRecurseSubmodulesError is a fetch error.
func NewOptionsCouldNotParseRecurseSubmodulesError(s string) error {
return fmt.Errorf("could not parse recurse_submodules value %q", s)
}
// NewFormatOverrideNotAllowedForDevNullError is a fetch error.
func NewFormatOverrideNotAllowedForDevNullError(devNull string) error {
return fmt.Errorf("not allowed if path is %s", devNull)
}
// NewInvalidPathError is a fetch error.
func NewInvalidPathError(format string, path string) error {
if format != "" {
format = format + " "
}
return fmt.Errorf("invalid %spath: %q", format, path)
}
// NewProtoFileCannotBeDevPathError is a fetch error.
func NewProtoFileCannotBeDevPathError(format string, path string) error {
if format != "" {
format = format + " "
}
return fmt.Errorf("invalid %spath: %q (protofiles cannot be read or written to or from stdio)", format, path)
}
// NewRealCleanPathError is a fetch error.
func NewRealCleanPathError(path string) error {
return fmt.Errorf("could not clean relative path %q", path)
}
// NewFormatUnknownError is a fetch error.
func NewFormatUnknownError(formatString string) error {
return fmt.Errorf("unknown format: %q", formatString)
}
// NewReadDisabledError is a fetch error.
func NewReadDisabledError(scheme string) error {
return fmt.Errorf("reading assets from %s disabled", scheme)
}
// NewReadHTTPDisabledError is a fetch error.
func NewReadHTTPDisabledError() error {
return NewReadDisabledError("http")
}
// NewReadGitDisabledError is a fetch error.
func NewReadGitDisabledError() error {
return NewReadDisabledError("git")
}
// NewReadLocalDisabledError is a fetch error.
func NewReadLocalDisabledError() error {
return NewReadDisabledError("local")
}
// NewReadStdioDisabledError is a fetch error.
func NewReadStdioDisabledError() error {
return NewReadDisabledError("stdin")
}
// NewReadModuleDisabledError is a fetch error.
func NewReadModuleDisabledError() error {
return NewReadDisabledError("module")
}
// NewWriteDisabledError is a fetch error.
func NewWriteDisabledError(scheme string) error {
return fmt.Errorf("writing assets to %s disabled", scheme)
}
// NewWriteHTTPDisabledError is a fetch error.
func NewWriteHTTPDisabledError() error {
return NewWriteDisabledError("http")
}
// NewWriteLocalDisabledError is a fetch error.
func NewWriteLocalDisabledError() error {
return NewWriteDisabledError("local")
}
// NewWriteStdioDisabledError is a fetch error.
func NewWriteStdioDisabledError() error {
return NewWriteDisabledError("stdout")
}
func newValueEmptyError() error {
return errors.New("required")
}
func newValueMultipleHashtagsError(value string) error {
return fmt.Errorf("%q has multiple #s which is invalid", value)
}
func newValueStartsWithHashtagError(value string) error {
return fmt.Errorf("%q starts with # which is invalid", value)
}
func newValueEndsWithHashtagError(value string) error {
return fmt.Errorf("%q ends with # which is invalid", value)
}
func newOptionsInvalidError(s string) error {
return fmt.Errorf("invalid options: %q", s)
}
func newOptionsDuplicateKeyError(key string) error {
return fmt.Errorf("duplicate options key: %q", key)
}