storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/object-api-errors.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2015, 2016, 2017, 2018 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "context" 21 "errors" 22 "fmt" 23 "io" 24 "path" 25 ) 26 27 // Converts underlying storage error. Convenience function written to 28 // handle all cases where we have known types of errors returned by 29 // underlying storage layer. 30 func toObjectErr(err error, params ...string) error { 31 switch err { 32 case errVolumeNotFound: 33 apiErr := BucketNotFound{} 34 if len(params) >= 1 { 35 apiErr.Bucket = params[0] 36 } 37 return apiErr 38 case errVolumeNotEmpty: 39 apiErr := BucketNotEmpty{} 40 if len(params) >= 1 { 41 apiErr.Bucket = params[0] 42 } 43 return apiErr 44 case errVolumeExists: 45 apiErr := BucketExists{} 46 if len(params) >= 1 { 47 apiErr.Bucket = params[0] 48 } 49 return apiErr 50 case errDiskFull: 51 return StorageFull{} 52 case errTooManyOpenFiles: 53 return SlowDown{} 54 case errFileAccessDenied: 55 apiErr := PrefixAccessDenied{} 56 if len(params) >= 1 { 57 apiErr.Bucket = params[0] 58 } 59 if len(params) >= 2 { 60 apiErr.Object = decodeDirObject(params[1]) 61 } 62 return apiErr 63 case errFileParentIsFile: 64 apiErr := ParentIsObject{} 65 if len(params) >= 1 { 66 apiErr.Bucket = params[0] 67 } 68 if len(params) >= 2 { 69 apiErr.Object = decodeDirObject(params[1]) 70 } 71 return apiErr 72 case errIsNotRegular: 73 apiErr := ObjectExistsAsDirectory{} 74 if len(params) >= 1 { 75 apiErr.Bucket = params[0] 76 } 77 if len(params) >= 2 { 78 apiErr.Object = decodeDirObject(params[1]) 79 } 80 return apiErr 81 case errFileVersionNotFound: 82 apiErr := VersionNotFound{} 83 if len(params) >= 1 { 84 apiErr.Bucket = params[0] 85 } 86 if len(params) >= 2 { 87 apiErr.Object = decodeDirObject(params[1]) 88 } 89 if len(params) >= 3 { 90 apiErr.VersionID = params[2] 91 } 92 return apiErr 93 case errMethodNotAllowed: 94 apiErr := MethodNotAllowed{} 95 if len(params) >= 1 { 96 apiErr.Bucket = params[0] 97 } 98 if len(params) >= 2 { 99 apiErr.Object = decodeDirObject(params[1]) 100 } 101 return apiErr 102 case errFileNotFound: 103 apiErr := ObjectNotFound{} 104 if len(params) >= 1 { 105 apiErr.Bucket = params[0] 106 } 107 if len(params) >= 2 { 108 apiErr.Object = decodeDirObject(params[1]) 109 } 110 return apiErr 111 case errUploadIDNotFound: 112 apiErr := InvalidUploadID{} 113 if len(params) >= 1 { 114 apiErr.Bucket = params[0] 115 } 116 if len(params) >= 2 { 117 apiErr.Object = decodeDirObject(params[1]) 118 } 119 if len(params) >= 3 { 120 apiErr.UploadID = params[2] 121 } 122 return apiErr 123 case errFileNameTooLong: 124 apiErr := ObjectNameInvalid{} 125 if len(params) >= 1 { 126 apiErr.Bucket = params[0] 127 } 128 if len(params) >= 2 { 129 apiErr.Object = decodeDirObject(params[1]) 130 } 131 return apiErr 132 case errDataTooLarge: 133 apiErr := ObjectTooLarge{} 134 if len(params) >= 1 { 135 apiErr.Bucket = params[0] 136 } 137 if len(params) >= 2 { 138 apiErr.Object = decodeDirObject(params[1]) 139 } 140 return apiErr 141 case errDataTooSmall: 142 apiErr := ObjectTooSmall{} 143 if len(params) >= 1 { 144 apiErr.Bucket = params[0] 145 } 146 if len(params) >= 2 { 147 apiErr.Object = decodeDirObject(params[1]) 148 } 149 return apiErr 150 case errErasureReadQuorum: 151 apiErr := InsufficientReadQuorum{} 152 if len(params) >= 1 { 153 apiErr.Bucket = params[0] 154 } 155 if len(params) >= 2 { 156 apiErr.Object = decodeDirObject(params[1]) 157 } 158 return apiErr 159 case errErasureWriteQuorum: 160 apiErr := InsufficientWriteQuorum{} 161 if len(params) >= 1 { 162 apiErr.Bucket = params[0] 163 } 164 if len(params) >= 2 { 165 apiErr.Object = decodeDirObject(params[1]) 166 } 167 return apiErr 168 case io.ErrUnexpectedEOF, io.ErrShortWrite: 169 return IncompleteBody{} 170 case context.Canceled, context.DeadlineExceeded: 171 return IncompleteBody{} 172 } 173 return err 174 } 175 176 // SignatureDoesNotMatch - when content md5 does not match with what was sent from client. 177 type SignatureDoesNotMatch struct{} 178 179 func (e SignatureDoesNotMatch) Error() string { 180 return "The request signature we calculated does not match the signature you provided. Check your key and signing method." 181 } 182 183 // StorageFull storage ran out of space. 184 type StorageFull struct{} 185 186 func (e StorageFull) Error() string { 187 return "Storage reached its minimum free disk threshold." 188 } 189 190 // SlowDown too many file descriptors open or backend busy . 191 type SlowDown struct{} 192 193 func (e SlowDown) Error() string { 194 return "Please reduce your request rate" 195 } 196 197 // InsufficientReadQuorum storage cannot satisfy quorum for read operation. 198 type InsufficientReadQuorum GenericError 199 200 func (e InsufficientReadQuorum) Error() string { 201 return "Storage resources are insufficient for the read operation " + e.Bucket + "/" + e.Object 202 } 203 204 // Unwrap the error. 205 func (e InsufficientReadQuorum) Unwrap() error { 206 return errErasureReadQuorum 207 } 208 209 // InsufficientWriteQuorum storage cannot satisfy quorum for write operation. 210 type InsufficientWriteQuorum GenericError 211 212 func (e InsufficientWriteQuorum) Error() string { 213 return "Storage resources are insufficient for the write operation " + e.Bucket + "/" + e.Object 214 } 215 216 // Unwrap the error. 217 func (e InsufficientWriteQuorum) Unwrap() error { 218 return errErasureWriteQuorum 219 } 220 221 // GenericError - generic object layer error. 222 type GenericError struct { 223 Bucket string 224 Object string 225 VersionID string 226 Err error 227 } 228 229 // Unwrap the error to its underlying error. 230 func (e GenericError) Unwrap() error { 231 return e.Err 232 } 233 234 // InvalidArgument incorrect input argument 235 type InvalidArgument GenericError 236 237 func (e InvalidArgument) Error() string { 238 if e.Err != nil { 239 return "Invalid arguments provided for " + e.Bucket + "/" + e.Object + ": (" + e.Err.Error() + ")" 240 } 241 return "Invalid arguments provided for " + e.Bucket + "/" + e.Object 242 } 243 244 // BucketNotFound bucket does not exist. 245 type BucketNotFound GenericError 246 247 func (e BucketNotFound) Error() string { 248 return "Bucket not found: " + e.Bucket 249 } 250 251 // BucketAlreadyExists the requested bucket name is not available. 252 type BucketAlreadyExists GenericError 253 254 func (e BucketAlreadyExists) Error() string { 255 return "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again." 256 } 257 258 // BucketAlreadyOwnedByYou already owned by you. 259 type BucketAlreadyOwnedByYou GenericError 260 261 func (e BucketAlreadyOwnedByYou) Error() string { 262 return "Bucket already owned by you: " + e.Bucket 263 } 264 265 // BucketNotEmpty bucket is not empty. 266 type BucketNotEmpty GenericError 267 268 func (e BucketNotEmpty) Error() string { 269 return "Bucket not empty: " + e.Bucket 270 } 271 272 // InvalidVersionID invalid version id 273 type InvalidVersionID GenericError 274 275 func (e InvalidVersionID) Error() string { 276 return "Invalid version id: " + e.Bucket + "/" + e.Object + "(" + e.VersionID + ")" 277 } 278 279 // VersionNotFound version does not exist. 280 type VersionNotFound GenericError 281 282 func (e VersionNotFound) Error() string { 283 return "Version not found: " + e.Bucket + "/" + e.Object + "(" + e.VersionID + ")" 284 } 285 286 // ObjectNotFound object does not exist. 287 type ObjectNotFound GenericError 288 289 func (e ObjectNotFound) Error() string { 290 return "Object not found: " + e.Bucket + "/" + e.Object 291 } 292 293 // MethodNotAllowed on the object 294 type MethodNotAllowed GenericError 295 296 func (e MethodNotAllowed) Error() string { 297 return "Method not allowed: " + e.Bucket + "/" + e.Object 298 } 299 300 // ObjectAlreadyExists object already exists. 301 type ObjectAlreadyExists GenericError 302 303 func (e ObjectAlreadyExists) Error() string { 304 return "Object: " + e.Bucket + "/" + e.Object + " already exists" 305 } 306 307 // ObjectExistsAsDirectory object already exists as a directory. 308 type ObjectExistsAsDirectory GenericError 309 310 func (e ObjectExistsAsDirectory) Error() string { 311 return "Object exists on : " + e.Bucket + " as directory " + e.Object 312 } 313 314 //PrefixAccessDenied object access is denied. 315 type PrefixAccessDenied GenericError 316 317 func (e PrefixAccessDenied) Error() string { 318 return "Prefix access is denied: " + e.Bucket + SlashSeparator + e.Object 319 } 320 321 // ParentIsObject object access is denied. 322 type ParentIsObject GenericError 323 324 func (e ParentIsObject) Error() string { 325 return "Parent is object " + e.Bucket + SlashSeparator + path.Dir(e.Object) 326 } 327 328 // BucketExists bucket exists. 329 type BucketExists GenericError 330 331 func (e BucketExists) Error() string { 332 return "Bucket exists: " + e.Bucket 333 } 334 335 // InvalidUploadIDKeyCombination - invalid upload id and key marker combination. 336 type InvalidUploadIDKeyCombination struct { 337 UploadIDMarker, KeyMarker string 338 } 339 340 func (e InvalidUploadIDKeyCombination) Error() string { 341 return fmt.Sprintf("Invalid combination of uploadID marker '%s' and marker '%s'", e.UploadIDMarker, e.KeyMarker) 342 } 343 344 // InvalidMarkerPrefixCombination - invalid marker and prefix combination. 345 type InvalidMarkerPrefixCombination struct { 346 Marker, Prefix string 347 } 348 349 func (e InvalidMarkerPrefixCombination) Error() string { 350 return fmt.Sprintf("Invalid combination of marker '%s' and prefix '%s'", e.Marker, e.Prefix) 351 } 352 353 // BucketPolicyNotFound - no bucket policy found. 354 type BucketPolicyNotFound GenericError 355 356 func (e BucketPolicyNotFound) Error() string { 357 return "No bucket policy configuration found for bucket: " + e.Bucket 358 } 359 360 // BucketLifecycleNotFound - no bucket lifecycle found. 361 type BucketLifecycleNotFound GenericError 362 363 func (e BucketLifecycleNotFound) Error() string { 364 return "No bucket lifecycle configuration found for bucket : " + e.Bucket 365 } 366 367 // BucketSSEConfigNotFound - no bucket encryption found 368 type BucketSSEConfigNotFound GenericError 369 370 func (e BucketSSEConfigNotFound) Error() string { 371 return "No bucket encryption configuration found for bucket: " + e.Bucket 372 } 373 374 // BucketTaggingNotFound - no bucket tags found 375 type BucketTaggingNotFound GenericError 376 377 func (e BucketTaggingNotFound) Error() string { 378 return "No bucket tags found for bucket: " + e.Bucket 379 } 380 381 // BucketObjectLockConfigNotFound - no bucket object lock config found 382 type BucketObjectLockConfigNotFound GenericError 383 384 func (e BucketObjectLockConfigNotFound) Error() string { 385 return "No bucket object lock configuration found for bucket: " + e.Bucket 386 } 387 388 // BucketQuotaConfigNotFound - no bucket quota config found. 389 type BucketQuotaConfigNotFound GenericError 390 391 func (e BucketQuotaConfigNotFound) Error() string { 392 return "No quota config found for bucket : " + e.Bucket 393 } 394 395 // BucketQuotaExceeded - bucket quota exceeded. 396 type BucketQuotaExceeded GenericError 397 398 func (e BucketQuotaExceeded) Error() string { 399 return "Bucket quota exceeded for bucket: " + e.Bucket 400 } 401 402 // BucketReplicationConfigNotFound - no bucket replication config found 403 type BucketReplicationConfigNotFound GenericError 404 405 func (e BucketReplicationConfigNotFound) Error() string { 406 return "The replication configuration was not found: " + e.Bucket 407 } 408 409 // BucketRemoteDestinationNotFound bucket does not exist. 410 type BucketRemoteDestinationNotFound GenericError 411 412 func (e BucketRemoteDestinationNotFound) Error() string { 413 return "Destination bucket does not exist: " + e.Bucket 414 } 415 416 // BucketReplicationDestinationMissingLock bucket does not have object lock enabled. 417 type BucketReplicationDestinationMissingLock GenericError 418 419 func (e BucketReplicationDestinationMissingLock) Error() string { 420 return "Destination bucket does not have object lock enabled: " + e.Bucket 421 } 422 423 // BucketRemoteTargetNotFound remote target does not exist. 424 type BucketRemoteTargetNotFound GenericError 425 426 func (e BucketRemoteTargetNotFound) Error() string { 427 return "Remote target not found: " + e.Bucket 428 } 429 430 // BucketRemoteConnectionErr remote target connection failure. 431 type BucketRemoteConnectionErr GenericError 432 433 func (e BucketRemoteConnectionErr) Error() string { 434 return fmt.Sprintf("Remote service endpoint or target bucket not available: %s \n\t%s", e.Bucket, e.Err.Error()) 435 } 436 437 // BucketRemoteAlreadyExists remote already exists for this target type. 438 type BucketRemoteAlreadyExists GenericError 439 440 func (e BucketRemoteAlreadyExists) Error() string { 441 return "Remote already exists for this bucket: " + e.Bucket 442 } 443 444 // BucketRemoteLabelInUse remote already exists for this target label. 445 type BucketRemoteLabelInUse GenericError 446 447 func (e BucketRemoteLabelInUse) Error() string { 448 return "Remote with this label already exists for this bucket: " + e.Bucket 449 } 450 451 // BucketRemoteArnTypeInvalid arn type for remote is not valid. 452 type BucketRemoteArnTypeInvalid GenericError 453 454 func (e BucketRemoteArnTypeInvalid) Error() string { 455 return "Remote ARN type not valid: " + e.Bucket 456 } 457 458 // BucketRemoteArnInvalid arn needs to be specified. 459 type BucketRemoteArnInvalid GenericError 460 461 func (e BucketRemoteArnInvalid) Error() string { 462 return "Remote ARN has invalid format: " + e.Bucket 463 } 464 465 // BucketRemoteRemoveDisallowed when replication configuration exists 466 type BucketRemoteRemoveDisallowed GenericError 467 468 func (e BucketRemoteRemoveDisallowed) Error() string { 469 return "Replication configuration exists with this ARN:" + e.Bucket 470 } 471 472 // BucketRemoteTargetNotVersioned remote target does not have versioning enabled. 473 type BucketRemoteTargetNotVersioned GenericError 474 475 func (e BucketRemoteTargetNotVersioned) Error() string { 476 return "Remote target does not have versioning enabled: " + e.Bucket 477 } 478 479 // BucketReplicationSourceNotVersioned replication source does not have versioning enabled. 480 type BucketReplicationSourceNotVersioned GenericError 481 482 func (e BucketReplicationSourceNotVersioned) Error() string { 483 return "Replication source does not have versioning enabled: " + e.Bucket 484 } 485 486 /// Bucket related errors. 487 488 // BucketNameInvalid - bucketname provided is invalid. 489 type BucketNameInvalid GenericError 490 491 // Error returns string an error formatted as the given text. 492 func (e BucketNameInvalid) Error() string { 493 return "Bucket name invalid: " + e.Bucket 494 } 495 496 /// Object related errors. 497 498 // ObjectNameInvalid - object name provided is invalid. 499 type ObjectNameInvalid GenericError 500 501 // ObjectNameTooLong - object name too long. 502 type ObjectNameTooLong GenericError 503 504 // ObjectNamePrefixAsSlash - object name has a slash as prefix. 505 type ObjectNamePrefixAsSlash GenericError 506 507 // Error returns string an error formatted as the given text. 508 func (e ObjectNameInvalid) Error() string { 509 return "Object name invalid: " + e.Bucket + "/" + e.Object 510 } 511 512 // Error returns string an error formatted as the given text. 513 func (e ObjectNameTooLong) Error() string { 514 return "Object name too long: " + e.Bucket + "/" + e.Object 515 } 516 517 // Error returns string an error formatted as the given text. 518 func (e ObjectNamePrefixAsSlash) Error() string { 519 return "Object name contains forward slash as pefix: " + e.Bucket + "/" + e.Object 520 } 521 522 // AllAccessDisabled All access to this object has been disabled 523 type AllAccessDisabled GenericError 524 525 // Error returns string an error formatted as the given text. 526 func (e AllAccessDisabled) Error() string { 527 return "All access to this object has been disabled" 528 } 529 530 // IncompleteBody You did not provide the number of bytes specified by the Content-Length HTTP header. 531 type IncompleteBody GenericError 532 533 // Error returns string an error formatted as the given text. 534 func (e IncompleteBody) Error() string { 535 return e.Bucket + "/" + e.Object + "has incomplete body" 536 } 537 538 // InvalidRange - invalid range typed error. 539 type InvalidRange struct { 540 OffsetBegin int64 541 OffsetEnd int64 542 ResourceSize int64 543 } 544 545 func (e InvalidRange) Error() string { 546 return fmt.Sprintf("The requested range \"bytes %d-%d/%d\" is not satisfiable.", e.OffsetBegin, e.OffsetEnd, e.ResourceSize) 547 } 548 549 // ObjectTooLarge error returned when the size of the object > max object size allowed (5G) per request. 550 type ObjectTooLarge GenericError 551 552 func (e ObjectTooLarge) Error() string { 553 return "size of the object greater than what is allowed(5G)" 554 } 555 556 // ObjectTooSmall error returned when the size of the object < what is expected. 557 type ObjectTooSmall GenericError 558 559 func (e ObjectTooSmall) Error() string { 560 return "size of the object less than what is expected" 561 } 562 563 // OperationTimedOut - a timeout occurred. 564 type OperationTimedOut struct { 565 } 566 567 func (e OperationTimedOut) Error() string { 568 return "Operation timed out" 569 } 570 571 /// Multipart related errors. 572 573 // MalformedUploadID malformed upload id. 574 type MalformedUploadID struct { 575 UploadID string 576 } 577 578 func (e MalformedUploadID) Error() string { 579 return "Malformed upload id " + e.UploadID 580 } 581 582 // InvalidUploadID invalid upload id. 583 type InvalidUploadID struct { 584 Bucket string 585 Object string 586 UploadID string 587 } 588 589 func (e InvalidUploadID) Error() string { 590 return "Invalid upload id " + e.UploadID 591 } 592 593 // InvalidPart One or more of the specified parts could not be found 594 type InvalidPart struct { 595 PartNumber int 596 ExpETag string 597 GotETag string 598 } 599 600 func (e InvalidPart) Error() string { 601 return fmt.Sprintf("Specified part could not be found. PartNumber %d, Expected %s, got %s", 602 e.PartNumber, e.ExpETag, e.GotETag) 603 } 604 605 // PartTooSmall - error if part size is less than 5MB. 606 type PartTooSmall struct { 607 PartSize int64 608 PartNumber int 609 PartETag string 610 } 611 612 func (e PartTooSmall) Error() string { 613 return fmt.Sprintf("Part size for %d should be at least 5MB", e.PartNumber) 614 } 615 616 // PartTooBig returned if size of part is bigger than the allowed limit. 617 type PartTooBig struct{} 618 619 func (e PartTooBig) Error() string { 620 return "Part size bigger than the allowed limit" 621 } 622 623 // InvalidETag error returned when the etag has changed on disk 624 type InvalidETag struct{} 625 626 func (e InvalidETag) Error() string { 627 return "etag of the object has changed" 628 } 629 630 // NotImplemented If a feature is not implemented 631 type NotImplemented struct { 632 Message string 633 } 634 635 func (e NotImplemented) Error() string { 636 return e.Message 637 } 638 639 // UnsupportedMetadata - unsupported metadata 640 type UnsupportedMetadata struct{} 641 642 func (e UnsupportedMetadata) Error() string { 643 return "Unsupported headers in Metadata" 644 } 645 646 // BackendDown is returned for network errors or if the gateway's backend is down. 647 type BackendDown struct{} 648 649 func (e BackendDown) Error() string { 650 return "Backend down" 651 } 652 653 // isErrBucketNotFound - Check if error type is BucketNotFound. 654 func isErrBucketNotFound(err error) bool { 655 var bkNotFound BucketNotFound 656 return errors.As(err, &bkNotFound) 657 } 658 659 // isErrObjectNotFound - Check if error type is ObjectNotFound. 660 func isErrObjectNotFound(err error) bool { 661 var objNotFound ObjectNotFound 662 return errors.As(err, &objNotFound) 663 } 664 665 // isErrVersionNotFound - Check if error type is VersionNotFound. 666 func isErrVersionNotFound(err error) bool { 667 var versionNotFound VersionNotFound 668 return errors.As(err, &versionNotFound) 669 } 670 671 // PreConditionFailed - Check if copy precondition failed 672 type PreConditionFailed struct{} 673 674 func (e PreConditionFailed) Error() string { 675 return "At least one of the pre-conditions you specified did not hold" 676 } 677 678 func isErrPreconditionFailed(err error) bool { 679 _, ok := err.(PreConditionFailed) 680 return ok 681 }