From bc8720406d00783d347d77f3f664f0d782fb1dce Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Sat, 9 Jul 2016 17:11:08 -0700 Subject: [PATCH] Added specific error for InvalidObjectName (#2157) --- api-errors.go | 8 +++++++- server_test.go | 2 +- test-utils_test.go | 2 +- xl-v1-utils.go | 6 +++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api-errors.go b/api-errors.go index 2f410eaa5..063c11ac7 100644 --- a/api-errors.go +++ b/api-errors.go @@ -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: diff --git a/server_test.go b/server_test.go index 82ac6e3f3..e4b3f5068 100644 --- a/server_test.go +++ b/server_test.go @@ -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 diff --git a/test-utils_test.go b/test-utils_test.go index f07ed8ab8..b7bf25041 100644 --- a/test-utils_test.go +++ b/test-utils_test.go @@ -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 diff --git a/xl-v1-utils.go b/xl-v1-utils.go index 039d91193..ba3d3c3ca 100644 --- a/xl-v1-utils.go +++ b/xl-v1-utils.go @@ -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