github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/client-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 "fmt" 22 "time" 23 ) 24 25 /// Collection of standard errors 26 27 // APINotImplemented - api not implemented 28 type APINotImplemented struct { 29 API string 30 APIType string 31 } 32 33 func (e APINotImplemented) Error() string { 34 return "`" + e.API + "` is not supported for `" + e.APIType + "`." 35 } 36 37 // InvalidArgument - passed argument is invalid for this operation 38 type InvalidArgument struct{} 39 40 func (e InvalidArgument) Error() string { 41 return "invalid argument" 42 } 43 44 // GenericBucketError - generic bucket operations error 45 type GenericBucketError struct { 46 Bucket string 47 } 48 49 // BucketDoesNotExist - bucket does not exist. 50 type BucketDoesNotExist GenericBucketError 51 52 func (e BucketDoesNotExist) Error() string { 53 return "Bucket `" + e.Bucket + "` does not exist." 54 } 55 56 // BucketExists - bucket exists. 57 type BucketExists GenericBucketError 58 59 func (e BucketExists) Error() string { 60 return "Bucket `" + e.Bucket + "` exists." 61 } 62 63 // BucketNameEmpty - bucket name empty (http://goo.gl/wJlzDz) 64 type BucketNameEmpty struct{} 65 66 func (e BucketNameEmpty) Error() string { 67 return "Bucket name cannot be empty." 68 } 69 70 // ObjectNameEmpty - object name empty. 71 type ObjectNameEmpty struct{} 72 73 func (e ObjectNameEmpty) Error() string { 74 return "Object name cannot be empty." 75 } 76 77 // BucketInvalid - bucket name invalid. 78 type BucketInvalid struct { 79 Bucket string 80 } 81 82 func (e BucketInvalid) Error() string { 83 return "Bucket name `" + e.Bucket + "` not valid." 84 } 85 86 // ObjectAlreadyExists - typed return for MethodNotAllowed 87 type ObjectAlreadyExists struct { 88 Object string 89 } 90 91 func (e ObjectAlreadyExists) Error() string { 92 return "Object `" + e.Object + "` already exists." 93 } 94 95 // ObjectAlreadyExistsAsDirectory - typed return for XMinioObjectExistsAsDirectory 96 type ObjectAlreadyExistsAsDirectory struct { 97 Object string 98 } 99 100 func (e ObjectAlreadyExistsAsDirectory) Error() string { 101 return "Object `" + e.Object + "` already exists as directory." 102 } 103 104 // ObjectOnGlacier - object is of storage class glacier. 105 type ObjectOnGlacier struct { 106 Object string 107 } 108 109 func (e ObjectOnGlacier) Error() string { 110 return "Object `" + e.Object + "` is on Glacier storage." 111 } 112 113 // GenericFileError - generic file error. 114 type GenericFileError struct { 115 Path string 116 } 117 118 // PathNotADirectory - this path does not correspond to a directory 119 type PathNotADirectory GenericFileError 120 121 func (e PathNotADirectory) Error() string { 122 return "Requested path `" + e.Path + "` not a directory" 123 } 124 125 // PathNotFound (ENOENT) - file not found. 126 type PathNotFound GenericFileError 127 128 func (e PathNotFound) Error() string { 129 return "Requested path `" + e.Path + "` not found" 130 } 131 132 // PathIsNotRegular (ENOTREG) - file is not a regular file. 133 type PathIsNotRegular GenericFileError 134 135 func (e PathIsNotRegular) Error() string { 136 return "Requested path `" + e.Path + "` is not a regular file." 137 } 138 139 // PathInsufficientPermission (EPERM) - permission denied. 140 type PathInsufficientPermission GenericFileError 141 142 func (e PathInsufficientPermission) Error() string { 143 return "Insufficient permissions to access this path `" + e.Path + "`" 144 } 145 146 // BrokenSymlink (ENOTENT) - file has broken symlink. 147 type BrokenSymlink GenericFileError 148 149 func (e BrokenSymlink) Error() string { 150 return "Requested path `" + e.Path + "` has broken symlink" 151 } 152 153 // TooManyLevelsSymlink (ELOOP) - file has too many levels of symlinks. 154 type TooManyLevelsSymlink GenericFileError 155 156 func (e TooManyLevelsSymlink) Error() string { 157 return "Requested path `" + e.Path + "` has too many levels of symlinks" 158 } 159 160 // EmptyPath (EINVAL) - invalid argument. 161 type EmptyPath struct{} 162 163 func (e EmptyPath) Error() string { 164 return "Invalid path, path cannot be empty" 165 } 166 167 // ObjectMissing (EINVAL) - object key missing. 168 type ObjectMissing struct { 169 timeRef time.Time 170 } 171 172 func (e ObjectMissing) Error() string { 173 if !e.timeRef.IsZero() { 174 return "Object did not exist at `" + e.timeRef.Format(time.RFC1123) + "`" 175 } 176 return "Object does not exist" 177 } 178 179 // ObjectIsDeleteMarker - object is a delete marker as latest 180 type ObjectIsDeleteMarker struct{} 181 182 func (e ObjectIsDeleteMarker) Error() string { 183 return "Object is marked as deleted" 184 } 185 186 // UnexpectedShortWrite - write wrote less bytes than expected. 187 type UnexpectedShortWrite struct { 188 InputSize int 189 WriteSize int 190 } 191 192 func (e UnexpectedShortWrite) Error() string { 193 msg := fmt.Sprintf("Wrote less data than requested. Expected `%d` bytes, but only wrote `%d` bytes.", e.InputSize, e.WriteSize) 194 return msg 195 } 196 197 // UnexpectedEOF (EPIPE) - reader closed prematurely. 198 type UnexpectedEOF struct { 199 TotalSize int64 200 TotalWritten int64 201 } 202 203 func (e UnexpectedEOF) Error() string { 204 msg := fmt.Sprintf("Input reader closed pre-maturely. Expected `%d` bytes, but only received `%d` bytes.", e.TotalSize, e.TotalWritten) 205 return msg 206 } 207 208 // UnexpectedExcessRead - reader wrote more data than requested. 209 type UnexpectedExcessRead UnexpectedEOF 210 211 func (e UnexpectedExcessRead) Error() string { 212 msg := fmt.Sprintf("Received excess data on input reader. Expected only `%d` bytes, but received `%d` bytes.", e.TotalSize, e.TotalWritten) 213 return msg 214 } 215 216 // SameFile - source and destination are same files. 217 type SameFile struct { 218 Source, Destination string 219 } 220 221 func (e SameFile) Error() string { 222 return fmt.Sprintf("'%s' and '%s' are the same file", e.Source, e.Destination) 223 }