Added specific error for InvalidObjectName (#2157)

This commit is contained in:
Krishnan Parthasarathi 2016-07-09 17:11:08 -07:00 committed by Harshavardhana
parent ae80f8ca35
commit bc8720406d
4 changed files with 12 additions and 6 deletions

View file

@ -115,6 +115,7 @@ const (
ErrStorageFull
ErrObjectExistsAsDirectory
ErrPolicyNesting
ErrInvalidObjectName
// Add new extended error codes here.
// Please open a https://github.com/minio/minio/issues before adding
// new error codes here.
@ -442,6 +443,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{
Description: "Policy nesting conflict has occurred.",
HTTPStatusCode: http.StatusConflict,
},
ErrInvalidObjectName: {
Code: "XMinioInvalidObjectName",
Description: "Object name contains unsupported characters. Unsupported characters are `^*|\\\"",
HTTPStatusCode: http.StatusBadRequest,
},
// Add your error structure here.
}
@ -483,7 +489,7 @@ func toAPIErrorCode(err error) (apiErr APIErrorCode) {
case ObjectNotFound:
apiErr = ErrNoSuchKey
case ObjectNameInvalid:
apiErr = ErrNotImplemented
apiErr = ErrInvalidObjectName
case InvalidUploadID:
apiErr = ErrNoSuchUpload
case InvalidPart:

View file

@ -878,7 +878,7 @@ func (s *TestSuiteCommon) TestPutObjectLongName(c *C) {
response, err = client.Do(request)
c.Assert(err, IsNil)
verifyError(c, response, "NotImplemented", "A header you provided implies functionality that is not implemented", http.StatusNotImplemented)
verifyError(c, response, "XMinioInvalidObjectName", "Object name contains unsupported characters. Unsupported characters are `^*|\\\"", http.StatusBadRequest)
}
// TestNotBeAbleToCreateObjectInNonexistentBucket - Validates the error response

View file

@ -364,7 +364,7 @@ type EOFWriter struct {
n int64
}
// io.Writer implementation desgined to error out with io.EOF after reading `n` bytes.
// io.Writer implementation designed to error out with io.EOF after reading `n` bytes.
func (t *EOFWriter) Write(p []byte) (n int, err error) {
if t.n <= 0 {
return -1, io.EOF

View file

@ -24,13 +24,13 @@ import (
)
// Returns nil even if one of the slice elements is nil.
// Else returns the error which occours the most.
// Else returns the error which occurs the most.
func reduceErrs(errs []error) error {
// In case the error type is not in the known error list.
var unknownErr = errors.New("unknown error")
var errTypes = []struct {
err error // error type
count int // occurance count
count int // occurrence count
}{
// List of known error types. Any new type that can be returned from StorageAPI should
// be added to this list. Most common errors are listed here.
@ -40,7 +40,7 @@ func reduceErrs(errs []error) error {
// unknownErr count - count of the number of unknown errors.
{unknownErr, 0},
}
// In case unknownErr count occours maximum number of times, unknownErrType is used to
// In case unknownErr count occurs maximum number of times, unknownErrType is used to
// to store it so that it can be used for the return error type.
var unknownErrType error