forked from bufbuild/buf
/
errors.go
172 lines (141 loc) · 5.18 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
// Copyright 2020-2023 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)
}
// NewCannotSpecifyGitBranchAndTagError is a fetch error.
func NewCannotSpecifyGitBranchAndTagError() error {
return errors.New(`must specify only one of "branch", "tag"`)
}
// NewCannotSpecifyTagWithRefError is a fetch error.
func NewCannotSpecifyTagWithRefError() error {
return errors.New(`cannot specify "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")
}
// NewOptionsInvalidKeyError is a fetch error.
func NewOptionsInvalidKeyError(key string) error {
return fmt.Errorf("invalid options key: %q", key)
}
// NewOptionsInvalidForFormatError is a fetch error.
func NewOptionsInvalidForFormatError(format string, s string) error {
return fmt.Errorf("invalid options for format %q: %q", format, s)
}
// 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)
}
// 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")
}