You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
364 lines
9.1 KiB
364 lines
9.1 KiB
10 years ago
|
/*
|
||
9 years ago
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
||
10 years ago
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
10 years ago
|
|
||
9 years ago
|
import (
|
||
8 years ago
|
"errors"
|
||
9 years ago
|
"fmt"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// Converts underlying storage error. Convenience function written to
|
||
|
// handle all cases where we have known types of errors returned by
|
||
|
// underlying storage layer.
|
||
|
func toObjectErr(err error, params ...string) error {
|
||
8 years ago
|
e, ok := err.(*Error)
|
||
|
if ok {
|
||
|
err = e.e
|
||
|
}
|
||
|
|
||
9 years ago
|
switch err {
|
||
|
case errVolumeNotFound:
|
||
|
if len(params) >= 1 {
|
||
8 years ago
|
err = BucketNotFound{Bucket: params[0]}
|
||
9 years ago
|
}
|
||
9 years ago
|
case errVolumeNotEmpty:
|
||
|
if len(params) >= 1 {
|
||
8 years ago
|
err = BucketNotEmpty{Bucket: params[0]}
|
||
9 years ago
|
}
|
||
9 years ago
|
case errVolumeExists:
|
||
|
if len(params) >= 1 {
|
||
8 years ago
|
err = BucketExists{Bucket: params[0]}
|
||
9 years ago
|
}
|
||
|
case errDiskFull:
|
||
8 years ago
|
err = StorageFull{}
|
||
8 years ago
|
case errFileAccessDenied:
|
||
|
if len(params) >= 2 {
|
||
|
err = PrefixAccessDenied{
|
||
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errIsNotRegular, errFileAccessDenied:
|
||
9 years ago
|
if len(params) >= 2 {
|
||
8 years ago
|
err = ObjectExistsAsDirectory{
|
||
9 years ago
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errFileNotFound:
|
||
9 years ago
|
if len(params) >= 2 {
|
||
8 years ago
|
err = ObjectNotFound{
|
||
9 years ago
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errFileNameTooLong:
|
||
|
if len(params) >= 2 {
|
||
8 years ago
|
err = ObjectNameInvalid{
|
||
9 years ago
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
8 years ago
|
case errDataTooLarge:
|
||
|
if len(params) >= 2 {
|
||
|
err = ObjectTooLarge{
|
||
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
8 years ago
|
case errDataTooSmall:
|
||
|
if len(params) >= 2 {
|
||
|
err = ObjectTooSmall{
|
||
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errXLReadQuorum:
|
||
8 years ago
|
err = InsufficientReadQuorum{}
|
||
9 years ago
|
case errXLWriteQuorum:
|
||
8 years ago
|
err = InsufficientWriteQuorum{}
|
||
9 years ago
|
case io.ErrUnexpectedEOF, io.ErrShortWrite:
|
||
8 years ago
|
err = IncompleteBody{}
|
||
8 years ago
|
case errContentSHA256Mismatch:
|
||
|
err = SHA256Mismatch{}
|
||
8 years ago
|
}
|
||
|
if ok {
|
||
|
e.e = err
|
||
|
return e
|
||
9 years ago
|
}
|
||
|
return err
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
// SHA256Mismatch - when content sha256 does not match with what was sent from client.
|
||
|
type SHA256Mismatch struct{}
|
||
|
|
||
|
func (e SHA256Mismatch) Error() string {
|
||
|
return "sha256 computed does not match with what is expected"
|
||
|
}
|
||
|
|
||
9 years ago
|
// StorageFull storage ran out of space.
|
||
9 years ago
|
type StorageFull struct{}
|
||
10 years ago
|
|
||
9 years ago
|
func (e StorageFull) Error() string {
|
||
|
return "Storage reached its minimum free disk threshold."
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// InsufficientReadQuorum storage cannot satisfy quorum for read operation.
|
||
|
type InsufficientReadQuorum struct{}
|
||
9 years ago
|
|
||
9 years ago
|
func (e InsufficientReadQuorum) Error() string {
|
||
9 years ago
|
return "Storage resources are insufficient for the read operation."
|
||
|
}
|
||
|
|
||
9 years ago
|
// InsufficientWriteQuorum storage cannot satisfy quorum for write operation.
|
||
|
type InsufficientWriteQuorum struct{}
|
||
9 years ago
|
|
||
9 years ago
|
func (e InsufficientWriteQuorum) Error() string {
|
||
|
return "Storage resources are insufficient for the write operation."
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// GenericError - generic object layer error.
|
||
|
type GenericError struct {
|
||
|
Bucket string
|
||
|
Object string
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// BucketNotFound bucket does not exist.
|
||
9 years ago
|
type BucketNotFound GenericError
|
||
10 years ago
|
|
||
|
func (e BucketNotFound) Error() string {
|
||
|
return "Bucket not found: " + e.Bucket
|
||
|
}
|
||
|
|
||
9 years ago
|
// BucketNotEmpty bucket is not empty.
|
||
9 years ago
|
type BucketNotEmpty GenericError
|
||
10 years ago
|
|
||
9 years ago
|
func (e BucketNotEmpty) Error() string {
|
||
|
return "Bucket not empty: " + e.Bucket
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// ObjectNotFound object does not exist.
|
||
9 years ago
|
type ObjectNotFound GenericError
|
||
10 years ago
|
|
||
|
func (e ObjectNotFound) Error() string {
|
||
9 years ago
|
return "Object not found: " + e.Bucket + "#" + e.Object
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// ObjectExistsAsDirectory object already exists as a directory.
|
||
|
type ObjectExistsAsDirectory GenericError
|
||
9 years ago
|
|
||
9 years ago
|
func (e ObjectExistsAsDirectory) Error() string {
|
||
|
return "Object exists on : " + e.Bucket + " as directory " + e.Object
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
//PrefixAccessDenied object access is denied.
|
||
|
type PrefixAccessDenied GenericError
|
||
|
|
||
|
func (e PrefixAccessDenied) Error() string {
|
||
|
return "Prefix access is denied: " + e.Bucket + "/" + e.Object
|
||
|
}
|
||
|
|
||
9 years ago
|
// BucketExists bucket exists.
|
||
9 years ago
|
type BucketExists GenericError
|
||
10 years ago
|
|
||
|
func (e BucketExists) Error() string {
|
||
|
return "Bucket exists: " + e.Bucket
|
||
|
}
|
||
|
|
||
9 years ago
|
// BadDigest - Content-MD5 you specified did not match what we received.
|
||
9 years ago
|
type BadDigest struct {
|
||
9 years ago
|
ExpectedMD5 string
|
||
|
CalculatedMD5 string
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
|
func (e BadDigest) Error() string {
|
||
9 years ago
|
return "Bad digest: Expected " + e.ExpectedMD5 + " is not valid with what we calculated " + e.CalculatedMD5
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// UnsupportedDelimiter - unsupported delimiter.
|
||
|
type UnsupportedDelimiter struct {
|
||
|
Delimiter string
|
||
|
}
|
||
|
|
||
|
func (e UnsupportedDelimiter) Error() string {
|
||
|
return fmt.Sprintf("delimiter '%s' is not supported. Only '/' is supported", e.Delimiter)
|
||
|
}
|
||
|
|
||
9 years ago
|
// InvalidUploadIDKeyCombination - invalid upload id and key marker combination.
|
||
9 years ago
|
type InvalidUploadIDKeyCombination struct {
|
||
|
UploadIDMarker, KeyMarker string
|
||
|
}
|
||
|
|
||
|
func (e InvalidUploadIDKeyCombination) Error() string {
|
||
|
return fmt.Sprintf("Invalid combination of uploadID marker '%s' and marker '%s'", e.UploadIDMarker, e.KeyMarker)
|
||
|
}
|
||
|
|
||
|
// InvalidMarkerPrefixCombination - invalid marker and prefix combination.
|
||
|
type InvalidMarkerPrefixCombination struct {
|
||
|
Marker, Prefix string
|
||
|
}
|
||
|
|
||
|
func (e InvalidMarkerPrefixCombination) Error() string {
|
||
|
return fmt.Sprintf("Invalid combination of marker '%s' and prefix '%s'", e.Marker, e.Prefix)
|
||
|
}
|
||
|
|
||
9 years ago
|
// BucketPolicyNotFound - no bucket policy found.
|
||
9 years ago
|
type BucketPolicyNotFound GenericError
|
||
9 years ago
|
|
||
|
func (e BucketPolicyNotFound) Error() string {
|
||
|
return "No bucket policy found for bucket: " + e.Bucket
|
||
|
}
|
||
|
|
||
9 years ago
|
/// Bucket related errors.
|
||
10 years ago
|
|
||
9 years ago
|
// BucketNameInvalid - bucketname provided is invalid.
|
||
9 years ago
|
type BucketNameInvalid GenericError
|
||
10 years ago
|
|
||
9 years ago
|
// Return string an error formatted as the given text.
|
||
10 years ago
|
func (e BucketNameInvalid) Error() string {
|
||
|
return "Bucket name invalid: " + e.Bucket
|
||
|
}
|
||
|
|
||
9 years ago
|
/// Object related errors.
|
||
9 years ago
|
|
||
9 years ago
|
// ObjectNameInvalid - object name provided is invalid.
|
||
9 years ago
|
type ObjectNameInvalid GenericError
|
||
|
|
||
9 years ago
|
// Return string an error formatted as the given text.
|
||
10 years ago
|
func (e ObjectNameInvalid) Error() string {
|
||
|
return "Object name invalid: " + e.Bucket + "#" + e.Object
|
||
|
}
|
||
|
|
||
9 years ago
|
// IncompleteBody You did not provide the number of bytes specified by the Content-Length HTTP header.
|
||
9 years ago
|
type IncompleteBody GenericError
|
||
10 years ago
|
|
||
9 years ago
|
// Return string an error formatted as the given text.
|
||
10 years ago
|
func (e IncompleteBody) Error() string {
|
||
|
return e.Bucket + "#" + e.Object + "has incomplete body"
|
||
|
}
|
||
|
|
||
8 years ago
|
// errInvalidRange - returned when given range value is not valid.
|
||
|
var errInvalidRange = errors.New("Invalid range")
|
||
|
|
||
|
// InvalidRange - invalid range typed error.
|
||
|
type InvalidRange struct {
|
||
|
offsetBegin int64
|
||
|
offsetEnd int64
|
||
|
resourceSize int64
|
||
|
}
|
||
|
|
||
|
func (e InvalidRange) Error() string {
|
||
|
return fmt.Sprintf("The requested range \"bytes %d-%d/%d\" is not satisfiable.", e.offsetBegin, e.offsetEnd, e.resourceSize)
|
||
|
}
|
||
|
|
||
8 years ago
|
// ObjectTooLarge error returned when the size of the object > max object size allowed (5G) per request.
|
||
|
type ObjectTooLarge GenericError
|
||
|
|
||
|
func (e ObjectTooLarge) Error() string {
|
||
|
return "size of the object greater than what is allowed(5G)"
|
||
|
}
|
||
|
|
||
8 years ago
|
// ObjectTooSmall error returned when the size of the object < what is expected.
|
||
|
type ObjectTooSmall GenericError
|
||
|
|
||
|
func (e ObjectTooSmall) Error() string {
|
||
|
return "size of the object less than what is expected"
|
||
|
}
|
||
|
|
||
9 years ago
|
/// Multipart related errors.
|
||
10 years ago
|
|
||
9 years ago
|
// MalformedUploadID malformed upload id.
|
||
|
type MalformedUploadID struct {
|
||
|
UploadID string
|
||
|
}
|
||
|
|
||
|
func (e MalformedUploadID) Error() string {
|
||
|
return "Malformed upload id " + e.UploadID
|
||
|
}
|
||
|
|
||
|
// InvalidUploadID invalid upload id.
|
||
10 years ago
|
type InvalidUploadID struct {
|
||
|
UploadID string
|
||
|
}
|
||
|
|
||
|
func (e InvalidUploadID) Error() string {
|
||
|
return "Invalid upload id " + e.UploadID
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
// InvalidPart One or more of the specified parts could not be found
|
||
|
type InvalidPart struct{}
|
||
|
|
||
|
func (e InvalidPart) Error() string {
|
||
|
return "One or more of the specified parts could not be found"
|
||
|
}
|
||
9 years ago
|
|
||
|
// PartTooSmall - error if part size is less than 5MB.
|
||
9 years ago
|
type PartTooSmall struct {
|
||
|
PartSize int64
|
||
|
PartNumber int
|
||
|
PartETag string
|
||
|
}
|
||
9 years ago
|
|
||
|
func (e PartTooSmall) Error() string {
|
||
9 years ago
|
return fmt.Sprintf("Part size for %d should be atleast 5MB", e.PartNumber)
|
||
9 years ago
|
}
|
||
8 years ago
|
|
||
|
// NotImplemented If a feature is not implemented
|
||
|
type NotImplemented struct{}
|
||
|
|
||
|
func (e NotImplemented) Error() string {
|
||
|
return "Not Implemented"
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
// PolicyNesting - policy nesting conflict.
|
||
|
type PolicyNesting struct{}
|
||
|
|
||
|
func (e PolicyNesting) Error() string {
|
||
|
return "New bucket policy conflicts with an existing policy. Please try again with new prefix."
|
||
|
}
|
||
|
|
||
8 years ago
|
// Check if error type is IncompleteBody.
|
||
|
func isErrIncompleteBody(err error) bool {
|
||
|
err = errorCause(err)
|
||
|
switch err.(type) {
|
||
|
case IncompleteBody:
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// Check if error type is BucketPolicyNotFound.
|
||
|
func isErrBucketPolicyNotFound(err error) bool {
|
||
|
err = errorCause(err)
|
||
|
switch err.(type) {
|
||
|
case BucketPolicyNotFound:
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
8 years ago
|
// Check if error type is ObjectNotFound.
|
||
|
func isErrObjectNotFound(err error) bool {
|
||
|
err = errorCause(err)
|
||
|
switch err.(type) {
|
||
|
case ObjectNotFound:
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|