/
typed-errors.go
193 lines (144 loc) · 5.89 KB
/
typed-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
// Copyright (c) 2015-2022 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"errors"
"fmt"
"strings"
"github.com/minio/mc/pkg/probe"
)
type dummyErr error
var errDummy = func() *probe.Error {
msg := ""
return probe.NewError(dummyErr(errors.New(msg))).Untrace()
}
type invalidArgumentErr error
var errInvalidArgument = func() *probe.Error {
msg := "Invalid arguments provided, please refer " + "`mc <command> -h` for relevant documentation."
return probe.NewError(invalidArgumentErr(errors.New(msg))).Untrace()
}
type unableToGuessErr error
var errUnableToGuess = func() *probe.Error {
msg := "Unable to guess the type of copy operation."
return probe.NewError(unableToGuessErr(errors.New(msg)))
}
type unrecognizedDiffTypeErr error
var errUnrecognizedDiffType = func(diff differType) *probe.Error {
msg := "Unrecognized diffType: " + diff.String() + " provided."
return probe.NewError(unrecognizedDiffTypeErr(errors.New(msg))).Untrace()
}
type invalidAliasedURLErr error
var errInvalidAliasedURL = func(URL string) *probe.Error {
msg := "Use `mc alias set mycloud " + URL + " ...` to add an alias. Use the alias for S3 operations."
return probe.NewError(invalidAliasedURLErr(errors.New(msg))).Untrace()
}
type invalidAliasErr error
var errInvalidAlias = func(alias string) *probe.Error {
msg := "Alias `" + alias + "` should have alphanumeric characters such as [helloWorld0, hello_World0, ...] and begin with a letter"
return probe.NewError(invalidAliasErr(errors.New(msg)))
}
type invalidURLErr error
var errInvalidURL = func(URL string) *probe.Error {
msg := "URL `" + URL + "` for MinIO Client should be of the form scheme://host[:port]/ without resource component."
return probe.NewError(invalidURLErr(errors.New(msg)))
}
type invalidAPISignatureErr error
var errInvalidAPISignature = func(api, url string) *probe.Error {
msg := fmt.Sprintf(
"Unrecognized API signature %s for host %s. Valid options are `[%s]`",
api, url, strings.Join(validAPIs, ", "))
return probe.NewError(invalidAPISignatureErr(errors.New(msg)))
}
type noMatchingHostErr error
var errNoMatchingHost = func(URL string) *probe.Error {
msg := "No matching host found for the given URL `" + URL + "`."
return probe.NewError(noMatchingHostErr(errors.New(msg))).Untrace()
}
type invalidSourceErr error
var errInvalidSource = func(URL string) *probe.Error {
msg := "Invalid source `" + URL + "`."
return probe.NewError(invalidSourceErr(errors.New(msg))).Untrace()
}
type invalidTargetErr error
var errInvalidTarget = func(URL string) *probe.Error {
msg := "Invalid target `" + URL + "`."
return probe.NewError(invalidTargetErr(errors.New(msg))).Untrace()
}
type requiresRecuriveErr error
var errRequiresRecursive = func(URL string) *probe.Error {
msg := "To copy or move '" + URL + "' the --recursive flag is required."
return probe.NewError(requiresRecuriveErr(errors.New(msg))).Untrace()
}
type copyIntoSelfErr error
var errCopyIntoSelf = func(URL string) *probe.Error {
msg := "Copying or moving '" + URL + "' into itself is not allowed."
return probe.NewError(copyIntoSelfErr(errors.New(msg))).Untrace()
}
type targetNotFoundErr error
var errTargetNotFound = func(URL string) *probe.Error {
msg := "Target `" + URL + "` not found."
return probe.NewError(targetNotFoundErr(errors.New(msg))).Untrace()
}
type overwriteNotAllowedErr struct {
error
}
var errOverWriteNotAllowed = func(URL string) *probe.Error {
msg := "Overwrite not allowed for `" + URL + "`. Use `--overwrite` to override this behavior."
return probe.NewError(overwriteNotAllowedErr{errors.New(msg)})
}
type targetIsNotDirErr error
var errTargetIsNotDir = func(URL string) *probe.Error {
msg := "Target `" + URL + "` is not a folder."
return probe.NewError(targetIsNotDirErr(errors.New(msg))).Untrace()
}
type sourceIsDirErr error
var errSourceIsDir = func(URL string) *probe.Error {
msg := "Source `" + URL + "` is a folder."
return probe.NewError(sourceIsDirErr(errors.New(msg))).Untrace()
}
type sseInvalidAliasErr error
var errSSEInvalidAlias = func(prefix string) *probe.Error {
msg := "SSE prefix " + prefix + " has an invalid alias."
return probe.NewError(sseInvalidAliasErr(errors.New(msg))).Untrace()
}
type sseOverlappingAliasErr error
var errSSEOverlappingAlias = func(prefix, overlappingPrefix string) *probe.Error {
msg := "SSE prefix " + prefix + " overlaps with " + overlappingPrefix
return probe.NewError(sseOverlappingAliasErr(errors.New(msg))).Untrace()
}
type ssePrefixMatchErr error
var errSSEPrefixMatch = func() *probe.Error {
msg := "SSE prefixes do not match any object paths."
return probe.NewError(ssePrefixMatchErr(errors.New(msg))).Untrace()
}
type sseKeyMissingError error
var errSSEKeyMissing = func() *probe.Error {
m := "SSE key is missing"
return probe.NewError(sseKeyMissingError(errors.New(m))).Untrace()
}
type sseKMSKeyFormatErr error
var errSSEKMSKeyFormat = func(msg string) *probe.Error {
m := "SSE key format error. "
m += msg
return probe.NewError(sseKMSKeyFormatErr(errors.New(m))).Untrace()
}
type sseClientKeyFormatErr error
var errSSEClientKeyFormat = func(msg string) *probe.Error {
m := "Encryption key should be 44 bytes raw base64 encoded key."
m += msg
return probe.NewError(sseClientKeyFormatErr(errors.New(m))).Untrace()
}