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.
267 lines
6.9 KiB
267 lines
6.9 KiB
10 years ago
|
/*
|
||
10 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 (
|
||
9 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 {
|
||
|
switch err {
|
||
|
case errVolumeNotFound:
|
||
|
if len(params) >= 1 {
|
||
|
return BucketNotFound{Bucket: params[0]}
|
||
|
}
|
||
9 years ago
|
case errVolumeNotEmpty:
|
||
|
if len(params) >= 1 {
|
||
|
return BucketNotEmpty{Bucket: params[0]}
|
||
|
}
|
||
9 years ago
|
case errVolumeExists:
|
||
|
if len(params) >= 1 {
|
||
|
return BucketExists{Bucket: params[0]}
|
||
|
}
|
||
|
case errDiskFull:
|
||
|
return StorageFull{}
|
||
9 years ago
|
case errIsNotRegular, errFileAccessDenied:
|
||
9 years ago
|
if len(params) >= 2 {
|
||
9 years ago
|
return ObjectExistsAsDirectory{
|
||
9 years ago
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errFileNotFound:
|
||
9 years ago
|
if len(params) >= 2 {
|
||
9 years ago
|
return ObjectNotFound{
|
||
9 years ago
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errFileNameTooLong:
|
||
|
if len(params) >= 2 {
|
||
|
return ObjectNameInvalid{
|
||
|
Bucket: params[0],
|
||
|
Object: params[1],
|
||
|
}
|
||
|
}
|
||
9 years ago
|
case errXLReadQuorum:
|
||
|
return InsufficientReadQuorum{}
|
||
|
case errXLWriteQuorum:
|
||
|
return InsufficientWriteQuorum{}
|
||
9 years ago
|
case io.ErrUnexpectedEOF, io.ErrShortWrite:
|
||
|
return IncompleteBody{}
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
10 years ago
|
|
||
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
|
}
|
||
|
|
||
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"
|
||
|
}
|
||
|
|
||
9 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)
|
||
|
}
|
||
|
|
||
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
|
|
||
10 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"
|
||
|
}
|