github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/typed-errors.go (about) 1 // Copyright (c) 2015-2022 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "errors" 22 "fmt" 23 "strings" 24 25 "github.com/minio/mc/pkg/probe" 26 ) 27 28 type dummyErr error 29 30 var errDummy = func() *probe.Error { 31 msg := "" 32 return probe.NewError(dummyErr(errors.New(msg))).Untrace() 33 } 34 35 type invalidArgumentErr error 36 37 var errInvalidArgument = func() *probe.Error { 38 msg := "Invalid arguments provided, please refer " + "`mc <command> -h` for relevant documentation." 39 return probe.NewError(invalidArgumentErr(errors.New(msg))).Untrace() 40 } 41 42 type unableToGuessErr error 43 44 var errUnableToGuess = func() *probe.Error { 45 msg := "Unable to guess the type of copy operation." 46 return probe.NewError(unableToGuessErr(errors.New(msg))) 47 } 48 49 type unrecognizedDiffTypeErr error 50 51 var errUnrecognizedDiffType = func(diff differType) *probe.Error { 52 msg := "Unrecognized diffType: " + diff.String() + " provided." 53 return probe.NewError(unrecognizedDiffTypeErr(errors.New(msg))).Untrace() 54 } 55 56 type invalidAliasedURLErr error 57 58 var errInvalidAliasedURL = func(URL string) *probe.Error { 59 msg := "Use `mc alias set mycloud " + URL + " ...` to add an alias. Use the alias for S3 operations." 60 return probe.NewError(invalidAliasedURLErr(errors.New(msg))).Untrace() 61 } 62 63 type invalidAliasErr error 64 65 var errInvalidAlias = func(alias string) *probe.Error { 66 msg := "Alias `" + alias + "` should have alphanumeric characters such as [helloWorld0, hello_World0, ...] and begin with a letter" 67 return probe.NewError(invalidAliasErr(errors.New(msg))) 68 } 69 70 type invalidURLErr error 71 72 var errInvalidURL = func(URL string) *probe.Error { 73 msg := "URL `" + URL + "` for MinIO Client should be of the form scheme://host[:port]/ without resource component." 74 return probe.NewError(invalidURLErr(errors.New(msg))) 75 } 76 77 type invalidAPISignatureErr error 78 79 var errInvalidAPISignature = func(api, url string) *probe.Error { 80 msg := fmt.Sprintf( 81 "Unrecognized API signature %s for host %s. Valid options are `[%s]`", 82 api, url, strings.Join(validAPIs, ", ")) 83 return probe.NewError(invalidAPISignatureErr(errors.New(msg))) 84 } 85 86 type noMatchingHostErr error 87 88 var errNoMatchingHost = func(URL string) *probe.Error { 89 msg := "No matching host found for the given URL `" + URL + "`." 90 return probe.NewError(noMatchingHostErr(errors.New(msg))).Untrace() 91 } 92 93 type invalidSourceErr error 94 95 var errInvalidSource = func(URL string) *probe.Error { 96 msg := "Invalid source `" + URL + "`." 97 return probe.NewError(invalidSourceErr(errors.New(msg))).Untrace() 98 } 99 100 type invalidTargetErr error 101 102 var errInvalidTarget = func(URL string) *probe.Error { 103 msg := "Invalid target `" + URL + "`." 104 return probe.NewError(invalidTargetErr(errors.New(msg))).Untrace() 105 } 106 107 type requiresRecuriveErr error 108 109 var errRequiresRecursive = func(URL string) *probe.Error { 110 msg := "To copy or move '" + URL + "' the --recursive flag is required." 111 return probe.NewError(requiresRecuriveErr(errors.New(msg))).Untrace() 112 } 113 114 type copyIntoSelfErr error 115 116 var errCopyIntoSelf = func(URL string) *probe.Error { 117 msg := "Copying or moving '" + URL + "' into itself is not allowed." 118 return probe.NewError(copyIntoSelfErr(errors.New(msg))).Untrace() 119 } 120 121 type targetNotFoundErr error 122 123 var errTargetNotFound = func(URL string) *probe.Error { 124 msg := "Target `" + URL + "` not found." 125 return probe.NewError(targetNotFoundErr(errors.New(msg))).Untrace() 126 } 127 128 type overwriteNotAllowedErr struct { 129 error 130 } 131 132 var errOverWriteNotAllowed = func(URL string) *probe.Error { 133 msg := "Overwrite not allowed for `" + URL + "`. Use `--overwrite` to override this behavior." 134 return probe.NewError(overwriteNotAllowedErr{errors.New(msg)}) 135 } 136 137 type targetIsNotDirErr error 138 139 var errTargetIsNotDir = func(URL string) *probe.Error { 140 msg := "Target `" + URL + "` is not a folder." 141 return probe.NewError(targetIsNotDirErr(errors.New(msg))).Untrace() 142 } 143 144 type sourceIsDirErr error 145 146 var errSourceIsDir = func(URL string) *probe.Error { 147 msg := "Source `" + URL + "` is a folder." 148 return probe.NewError(sourceIsDirErr(errors.New(msg))).Untrace() 149 } 150 151 type sseInvalidAliasErr error 152 153 var errSSEInvalidAlias = func(prefix string) *probe.Error { 154 msg := "SSE prefix " + prefix + " has an invalid alias." 155 return probe.NewError(sseInvalidAliasErr(errors.New(msg))).Untrace() 156 } 157 158 type sseOverlappingAliasErr error 159 160 var errSSEOverlappingAlias = func(prefix, overlappingPrefix string) *probe.Error { 161 msg := "SSE prefix " + prefix + " overlaps with " + overlappingPrefix 162 return probe.NewError(sseOverlappingAliasErr(errors.New(msg))).Untrace() 163 } 164 165 type ssePrefixMatchErr error 166 167 var errSSEPrefixMatch = func() *probe.Error { 168 msg := "SSE prefixes do not match any object paths." 169 return probe.NewError(ssePrefixMatchErr(errors.New(msg))).Untrace() 170 } 171 172 type sseKeyMissingError error 173 174 var errSSEKeyMissing = func() *probe.Error { 175 m := "SSE key is missing" 176 return probe.NewError(sseKeyMissingError(errors.New(m))).Untrace() 177 } 178 179 type sseKMSKeyFormatErr error 180 181 var errSSEKMSKeyFormat = func(msg string) *probe.Error { 182 m := "SSE key format error. " 183 m += msg 184 return probe.NewError(sseKMSKeyFormatErr(errors.New(m))).Untrace() 185 } 186 187 type sseClientKeyFormatErr error 188 189 var errSSEClientKeyFormat = func(msg string) *probe.Error { 190 m := "Encryption key should be 44 bytes raw base64 encoded key." 191 m += msg 192 return probe.NewError(sseClientKeyFormatErr(errors.New(m))).Untrace() 193 }