Skip to content

Commit

Permalink
Unexport some ErrorResponse generator functions (minio#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadmeste authored Jul 1, 2020
1 parent a1a842a commit b76e654
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 144 deletions.
28 changes: 14 additions & 14 deletions api-compose-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func filterCustomMeta(userMeta map[string]string) (map[string]string, error) {
k = k[len("x-amz-meta-"):]
}
if _, ok := m[k]; ok {
return nil, ErrInvalidArgument(fmt.Sprintf("Cannot add both %s and x-amz-meta-%s keys as custom metadata", k, k))
return nil, errInvalidArgument(fmt.Sprintf("Cannot add both %s and x-amz-meta-%s keys as custom metadata", k, k))
}
m[k] = v
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func NewSourceInfo(bucket, object string, sse encrypt.ServerSide) SourceInfo {
// copied.
func (s *SourceInfo) SetRange(start, end int64) error {
if start > end || start < 0 {
return ErrInvalidArgument("start must be non-negative, and start must be at most end.")
return errInvalidArgument("start must be non-negative, and start must be at most end.")
}
// Note that 0 <= start <= end
s.start, s.end = start, end
Expand All @@ -216,7 +216,7 @@ func (s *SourceInfo) SetRange(start, end int64) error {
// only if the etag of the source matches the value given here.
func (s *SourceInfo) SetMatchETagCond(etag string) error {
if etag == "" {
return ErrInvalidArgument("ETag cannot be empty.")
return errInvalidArgument("ETag cannot be empty.")
}
s.Headers.Set("x-amz-copy-source-if-match", etag)
return nil
Expand All @@ -227,7 +227,7 @@ func (s *SourceInfo) SetMatchETagCond(etag string) error {
// not the value given here.
func (s *SourceInfo) SetMatchETagExceptCond(etag string) error {
if etag == "" {
return ErrInvalidArgument("ETag cannot be empty.")
return errInvalidArgument("ETag cannot be empty.")
}
s.Headers.Set("x-amz-copy-source-if-none-match", etag)
return nil
Expand All @@ -236,7 +236,7 @@ func (s *SourceInfo) SetMatchETagExceptCond(etag string) error {
// SetModifiedSinceCond - Set the modified since condition.
func (s *SourceInfo) SetModifiedSinceCond(modTime time.Time) error {
if modTime.IsZero() {
return ErrInvalidArgument("Input time cannot be 0.")
return errInvalidArgument("Input time cannot be 0.")
}
s.Headers.Set("x-amz-copy-source-if-modified-since", modTime.Format(http.TimeFormat))
return nil
Expand All @@ -245,7 +245,7 @@ func (s *SourceInfo) SetModifiedSinceCond(modTime time.Time) error {
// SetUnmodifiedSinceCond - Set the unmodified since condition.
func (s *SourceInfo) SetUnmodifiedSinceCond(modTime time.Time) error {
if modTime.IsZero() {
return ErrInvalidArgument("Input time cannot be 0.")
return errInvalidArgument("Input time cannot be 0.")
}
s.Headers.Set("x-amz-copy-source-if-unmodified-since", modTime.Format(http.TimeFormat))
return nil
Expand All @@ -259,7 +259,7 @@ func (s *SourceInfo) getProps(c Client) (size int64, etag string, userMeta map[s
opts := StatObjectOptions{GetObjectOptions{ServerSideEncryption: encrypt.SSE(s.encryption)}}
objInfo, err = c.statObject(context.Background(), s.bucket, s.object, opts)
if err != nil {
err = ErrInvalidArgument(fmt.Sprintf("Could not stat object - %s/%s: %v", s.bucket, s.object, err))
err = errInvalidArgument(fmt.Sprintf("Could not stat object - %s/%s: %v", s.bucket, s.object, err))
} else {
size = objInfo.Size
etag = objInfo.ETag
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c Client) copyObjectPartDo(ctx context.Context, srcBucket, srcObject, dest
headers.Set("x-amz-copy-source", s3utils.EncodePath(srcBucket+"/"+srcObject))

if startOffset < 0 {
return p, ErrInvalidArgument("startOffset must be non-negative")
return p, errInvalidArgument("startOffset must be non-negative")
}

if length >= 0 {
Expand Down Expand Up @@ -415,7 +415,7 @@ func (c Client) uploadPartCopy(ctx context.Context, bucket, object, uploadID str
// look at current progress.
func (c Client) ComposeObjectWithProgress(ctx context.Context, dst DestinationInfo, srcs []SourceInfo, progress io.Reader) error {
if len(srcs) < 1 || len(srcs) > maxPartsCount {
return ErrInvalidArgument("There must be as least one and up to 10000 source objects.")
return errInvalidArgument("There must be as least one and up to 10000 source objects.")
}
srcSizes := make([]int64, len(srcs))
var totalSize, size, totalParts int64
Expand All @@ -431,7 +431,7 @@ func (c Client) ComposeObjectWithProgress(ctx context.Context, dst DestinationIn
// Error out if client side encryption is used in this source object when
// more than one source objects are given.
if len(srcs) > 1 && src.Headers.Get("x-amz-meta-x-amz-key") != "" {
return ErrInvalidArgument(
return errInvalidArgument(
fmt.Sprintf("Client side encryption is used in source object %s/%s", src.bucket, src.object))
}

Expand All @@ -442,7 +442,7 @@ func (c Client) ComposeObjectWithProgress(ctx context.Context, dst DestinationIn
// 0 <= src.start <= src.end
// so only invalid case to check is:
if src.end >= size {
return ErrInvalidArgument(
return errInvalidArgument(
fmt.Sprintf("SourceInfo %d has invalid segment-to-copy [%d, %d] (size is %d)",
i, src.start, src.end, size))
}
Expand All @@ -451,14 +451,14 @@ func (c Client) ComposeObjectWithProgress(ctx context.Context, dst DestinationIn

// Only the last source may be less than `absMinPartSize`
if size < absMinPartSize && i < len(srcs)-1 {
return ErrInvalidArgument(
return errInvalidArgument(
fmt.Sprintf("SourceInfo %d is too small (%d) and it is not the last part", i, size))
}

// Is data to copy too large?
totalSize += size
if totalSize > maxMultipartPutObjectSize {
return ErrInvalidArgument(fmt.Sprintf("Cannot compose an object of size %d (> 5TiB)", totalSize))
return errInvalidArgument(fmt.Sprintf("Cannot compose an object of size %d (> 5TiB)", totalSize))
}

// record source size
Expand All @@ -468,7 +468,7 @@ func (c Client) ComposeObjectWithProgress(ctx context.Context, dst DestinationIn
totalParts += partsRequired(size)
// Do we need more parts than we are allowed?
if totalParts > maxPartsCount {
return ErrInvalidArgument(fmt.Sprintf(
return errInvalidArgument(fmt.Sprintf(
"Your proposed compose object requires more than %d parts", maxPartsCount))
}
}
Expand Down
51 changes: 18 additions & 33 deletions api-error-response.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2017 MinIO, Inc.
* Copyright 2015-2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,7 +103,7 @@ const (
func httpRespToErrorResponse(resp *http.Response, bucketName, objectName string) error {
if resp == nil {
msg := "Response is empty. " + reportIssue
return ErrInvalidArgument(msg)
return errInvalidArgument(msg)
}

errResp := ErrorResponse{
Expand Down Expand Up @@ -183,8 +183,8 @@ func httpRespToErrorResponse(resp *http.Response, bucketName, objectName string)
return errResp
}

// ErrTransferAccelerationBucket - bucket name is invalid to be used with transfer acceleration.
func ErrTransferAccelerationBucket(bucketName string) error {
// errTransferAccelerationBucket - bucket name is invalid to be used with transfer acceleration.
func errTransferAccelerationBucket(bucketName string) error {
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "InvalidArgument",
Expand All @@ -193,8 +193,8 @@ func ErrTransferAccelerationBucket(bucketName string) error {
}
}

// ErrEntityTooLarge - Input size is larger than supported maximum.
func ErrEntityTooLarge(totalSize, maxObjectSize int64, bucketName, objectName string) error {
// errEntityTooLarge - Input size is larger than supported maximum.
func errEntityTooLarge(totalSize, maxObjectSize int64, bucketName, objectName string) error {
msg := fmt.Sprintf("Your proposed upload size ‘%d’ exceeds the maximum allowed object size ‘%d’ for single PUT operation.", totalSize, maxObjectSize)
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Expand All @@ -205,8 +205,8 @@ func ErrEntityTooLarge(totalSize, maxObjectSize int64, bucketName, objectName st
}
}

// ErrEntityTooSmall - Input size is smaller than supported minimum.
func ErrEntityTooSmall(totalSize int64, bucketName, objectName string) error {
// errEntityTooSmall - Input size is smaller than supported minimum.
func errEntityTooSmall(totalSize int64, bucketName, objectName string) error {
msg := fmt.Sprintf("Your proposed upload size ‘%d’ is below the minimum allowed object size ‘0B’ for single PUT operation.", totalSize)
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Expand All @@ -217,8 +217,8 @@ func ErrEntityTooSmall(totalSize int64, bucketName, objectName string) error {
}
}

// ErrUnexpectedEOF - Unexpected end of file reached.
func ErrUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string) error {
// errUnexpectedEOF - Unexpected end of file reached.
func errUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string) error {
msg := fmt.Sprintf("Data read ‘%d’ is not equal to the size ‘%d’ of the input Reader.", totalRead, totalSize)
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Expand All @@ -229,8 +229,8 @@ func ErrUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string)
}
}

// ErrInvalidBucketName - Invalid bucket name response.
func ErrInvalidBucketName(message string) error {
// errInvalidBucketName - Invalid bucket name response.
func errInvalidBucketName(message string) error {
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "InvalidBucketName",
Expand All @@ -239,8 +239,8 @@ func ErrInvalidBucketName(message string) error {
}
}

// ErrInvalidObjectName - Invalid object name response.
func ErrInvalidObjectName(message string) error {
// errInvalidObjectName - Invalid object name response.
func errInvalidObjectName(message string) error {
return ErrorResponse{
StatusCode: http.StatusNotFound,
Code: "NoSuchKey",
Expand All @@ -249,12 +249,8 @@ func ErrInvalidObjectName(message string) error {
}
}

// ErrInvalidObjectPrefix - Invalid object prefix response is
// similar to object name response.
var ErrInvalidObjectPrefix = ErrInvalidObjectName

// ErrInvalidArgument - Invalid argument response.
func ErrInvalidArgument(message string) error {
// errInvalidArgument - Invalid argument response.
func errInvalidArgument(message string) error {
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "InvalidArgument",
Expand All @@ -263,20 +259,9 @@ func ErrInvalidArgument(message string) error {
}
}

// ErrNoSuchBucketPolicy - No Such Bucket Policy response
// The specified bucket does not have a bucket policy.
func ErrNoSuchBucketPolicy(message string) error {
return ErrorResponse{
StatusCode: http.StatusNotFound,
Code: "NoSuchBucketPolicy",
Message: message,
RequestID: "minio",
}
}

// ErrAPINotSupported - API not supported response
// errAPINotSupported - API not supported response
// The specified API call is not supported
func ErrAPINotSupported(message string) error {
func errAPINotSupported(message string) error {
return ErrorResponse{
StatusCode: http.StatusNotImplemented,
Code: "APINotSupported",
Expand Down
12 changes: 6 additions & 6 deletions api-error-response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestErrEntityTooLarge(t *testing.T) {
BucketName: "minio-bucket",
Key: "Asia/",
}
actualResult := ErrEntityTooLarge(1000000, 99999, "minio-bucket", "Asia/")
actualResult := errEntityTooLarge(1000000, 99999, "minio-bucket", "Asia/")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand All @@ -209,7 +209,7 @@ func TestErrEntityTooSmall(t *testing.T) {
BucketName: "minio-bucket",
Key: "Asia/",
}
actualResult := ErrEntityTooSmall(-1, "minio-bucket", "Asia/")
actualResult := errEntityTooSmall(-1, "minio-bucket", "Asia/")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand All @@ -226,7 +226,7 @@ func TestErrUnexpectedEOF(t *testing.T) {
BucketName: "minio-bucket",
Key: "Asia/",
}
actualResult := ErrUnexpectedEOF(100, 101, "minio-bucket", "Asia/")
actualResult := errUnexpectedEOF(100, 101, "minio-bucket", "Asia/")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand All @@ -240,7 +240,7 @@ func TestErrInvalidBucketName(t *testing.T) {
Message: "Invalid Bucket name",
RequestID: "minio",
}
actualResult := ErrInvalidBucketName("Invalid Bucket name")
actualResult := errInvalidBucketName("Invalid Bucket name")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand All @@ -254,7 +254,7 @@ func TestErrInvalidObjectName(t *testing.T) {
Message: "Invalid Object Key",
RequestID: "minio",
}
actualResult := ErrInvalidObjectName("Invalid Object Key")
actualResult := errInvalidObjectName("Invalid Object Key")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand All @@ -268,7 +268,7 @@ func TestErrInvalidArgument(t *testing.T) {
Message: "Invalid Argument",
RequestID: "minio",
}
actualResult := ErrInvalidArgument("Invalid Argument")
actualResult := errInvalidArgument("Invalid Argument")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
Expand Down
2 changes: 1 addition & 1 deletion api-get-object-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c Client) FGetObject(ctx context.Context, bucketName, objectName, filePath
if err == nil {
// If the destination exists and is a directory.
if st.IsDir() {
return ErrInvalidArgument("fileName is a directory.")
return errInvalidArgument("fileName is a directory.")
}
}

Expand Down
18 changes: 9 additions & 9 deletions api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (o *Object) setOffset(bytesRead int64) error {
// io.EOF upon end of file.
func (o *Object) Read(b []byte) (n int, err error) {
if o == nil {
return 0, ErrInvalidArgument("Object is nil")
return 0, errInvalidArgument("Object is nil")
}

// Locking.
Expand Down Expand Up @@ -371,7 +371,7 @@ func (o *Object) Read(b []byte) (n int, err error) {
// Stat returns the ObjectInfo structure describing Object.
func (o *Object) Stat() (ObjectInfo, error) {
if o == nil {
return ObjectInfo{}, ErrInvalidArgument("Object is nil")
return ObjectInfo{}, errInvalidArgument("Object is nil")
}
// Locking.
o.mutex.Lock()
Expand Down Expand Up @@ -403,7 +403,7 @@ func (o *Object) Stat() (ObjectInfo, error) {
// file, that error is io.EOF.
func (o *Object) ReadAt(b []byte, offset int64) (n int, err error) {
if o == nil {
return 0, ErrInvalidArgument("Object is nil")
return 0, errInvalidArgument("Object is nil")
}

// Locking.
Expand Down Expand Up @@ -480,7 +480,7 @@ func (o *Object) ReadAt(b []byte, offset int64) (n int, err error) {
// underlying object is not closed.
func (o *Object) Seek(offset int64, whence int) (n int64, err error) {
if o == nil {
return 0, ErrInvalidArgument("Object is nil")
return 0, errInvalidArgument("Object is nil")
}

// Locking.
Expand All @@ -494,7 +494,7 @@ func (o *Object) Seek(offset int64, whence int) (n int64, err error) {

// Negative offset is valid for whence of '2'.
if offset < 0 && whence != 2 {
return 0, ErrInvalidArgument(fmt.Sprintf("Negative position not allowed for %d", whence))
return 0, errInvalidArgument(fmt.Sprintf("Negative position not allowed for %d", whence))
}

// This is the first request. So before anything else
Expand All @@ -518,7 +518,7 @@ func (o *Object) Seek(offset int64, whence int) (n int64, err error) {
// Switch through whence.
switch whence {
default:
return 0, ErrInvalidArgument(fmt.Sprintf("Invalid whence %d", whence))
return 0, errInvalidArgument(fmt.Sprintf("Invalid whence %d", whence))
case 0:
if o.objectInfo.Size > -1 && offset > o.objectInfo.Size {
return 0, io.EOF
Expand All @@ -532,7 +532,7 @@ func (o *Object) Seek(offset int64, whence int) (n int64, err error) {
case 2:
// If we don't know the object size return an error for io.SeekEnd
if o.objectInfo.Size < 0 {
return 0, ErrInvalidArgument("Whence END is not supported when the object size is unknown")
return 0, errInvalidArgument("Whence END is not supported when the object size is unknown")
}
// Seeking to positive offset is valid for whence '2', but
// since we are backing a Reader we have reached 'EOF' if
Expand All @@ -542,7 +542,7 @@ func (o *Object) Seek(offset int64, whence int) (n int64, err error) {
}
// Seeking to negative position not allowed for whence.
if o.objectInfo.Size+offset < 0 {
return 0, ErrInvalidArgument(fmt.Sprintf("Seeking at negative offset not allowed for %d", whence))
return 0, errInvalidArgument(fmt.Sprintf("Seeking at negative offset not allowed for %d", whence))
}
o.currOffset = o.objectInfo.Size + offset
}
Expand All @@ -563,7 +563,7 @@ func (o *Object) Seek(offset int64, whence int) (n int64, err error) {
// for subsequent Close() calls.
func (o *Object) Close() (err error) {
if o == nil {
return ErrInvalidArgument("Object is nil")
return errInvalidArgument("Object is nil")
}
// Locking.
o.mutex.Lock()
Expand Down
Loading

0 comments on commit b76e654

Please sign in to comment.