diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-03-08 23:02:44 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-03-08 23:02:44 +0100 |
| commit | 9e8ed9ef479ca2084d9e34edfda0a99be34dbdb5 (patch) | |
| tree | a07542caa4dfc3ccd2fe058f27ccadf3a459e91a | |
| parent | 0a9bb149419c4df0be820f2cb72c8cc7e3332c68 (diff) | |
| download | go-schwift-9e8ed9ef479ca2084d9e34edfda0a99be34dbdb5.tar.gz | |
generalize BulkUploadError into BulkError
For use in Account.BulkDelete().
| -rw-r--r-- | bulk.go | 12 | ||||
| -rw-r--r-- | errors.go | 28 | ||||
| -rw-r--r-- | object.go | 2 | ||||
| -rw-r--r-- | tests/bulk_upload_test.go (renamed from tests/bulk_test.go) | 6 |
4 files changed, 25 insertions, 23 deletions
@@ -56,7 +56,7 @@ const ( //exceeded in the middle of the archive extraction). // //If not nil, the error return value is *usually* an instance of -//schwift.BulkUploadError. +//BulkError. // //This operation returns (0, ErrNotSupported) if the server does not support //bulk-uploading. @@ -114,9 +114,9 @@ func (a *Account) BulkUpload(uploadPath string, format BulkUploadFormat, content return 0, err } - //parse `result` into type BulkUploadError - bulkErr := BulkUploadError{ - ArchiveError: result.ResponseBody, + //parse `result` into type BulkError + bulkErr := BulkError{ + OverallError: result.ResponseBody, } bulkErr.StatusCode, err = parseResponseStatus(result.ResponseStatus) if err != nil { @@ -141,8 +141,8 @@ func (a *Account) BulkUpload(uploadPath string, format BulkUploadFormat, content }) } - //is BulkUploadError really an error? - if len(bulkErr.ObjectErrors) == 0 && bulkErr.ArchiveError == "" && bulkErr.StatusCode >= 200 && bulkErr.StatusCode < 300 { + //is BulkError really an error? + if len(bulkErr.ObjectErrors) == 0 && bulkErr.OverallError == "" && bulkErr.StatusCode >= 200 && bulkErr.StatusCode < 300 { return result.NumberFilesCreated, nil } return result.NumberFilesCreated, bulkErr @@ -66,7 +66,7 @@ func (e UnexpectedStatusCodeError) Error() string { } //BulkObjectError is the error message for a single object in a bulk operation. -//It is not generated individually, only as part of BulkUploadError and BulkDeleteError. +//It is not generated individually, only as part of BulkError. type BulkObjectError struct { ContainerName string ObjectName string @@ -81,27 +81,27 @@ func (e BulkObjectError) Error() string { ) } -//BulkUploadError is returned by Account.BulkUpload() when the archive was -//uploaded and unpacked successfully, but some (or all) files could not be -//saved in Swift. -type BulkUploadError struct { +//BulkError is returned by Account.BulkUpload() when the archive was +//uploaded and unpacked successfully, but some (or all) objects could not be +//saved in Swift; and by Account.BulkDelete() when not all requested objects +//could be deleted. +type BulkError struct { //StatusCode contains the overall HTTP status code of the operation. StatusCode int - //ArchiveError contains the error that occurred while unpacking the archive, - //or if the archive as a whole was not acceptable. If may be empty if no - //error occurred at this point. - ArchiveError string - //ObjectErrors contains errors that occurred while trying to save an - //individual file from the archive. It may be empty. + //OverallError contains the fatal error that aborted the bulk operation, or a + //summary of which recoverable errors were encountered. It may be empty. + OverallError string + //ObjectErrors contains errors that occurred while working on individual + //objects. It may be empty if no such errors occurred. ObjectErrors []BulkObjectError } //Error implements the builtin/error interface. To fit into one line, it //condenses the ObjectErrors into a count. -func (e BulkUploadError) Error() string { +func (e BulkError) Error() string { result := fmt.Sprintf("%d %s", e.StatusCode, http.StatusText(e.StatusCode)) - if e.ArchiveError != "" { - result += ": " + e.ArchiveError + if e.OverallError != "" { + result += ": " + e.OverallError } if len(e.ObjectErrors) > 0 { result += fmt.Sprintf(" (+%d object errors)", len(e.ObjectErrors)) @@ -207,6 +207,8 @@ func (o *Object) Upload(content io.Reader, headers ObjectHeaders, opts *RequestO return nil } +//TODO add support for strings.Reader below + func tryComputeContentLength(content io.Reader, headers ObjectHeaders) { h := headers.SizeBytes() if h.Exists() { diff --git a/tests/bulk_test.go b/tests/bulk_upload_test.go index b7f1e77..68cb791 100644 --- a/tests/bulk_test.go +++ b/tests/bulk_upload_test.go @@ -62,9 +62,9 @@ func TestBulkUploadArchiveError(t *testing.T) { ) expectInt(t, n, 0) expectError(t, err, "400 Bad Request: Invalid Tar File: truncated header") - bulkErr := err.(schwift.BulkUploadError) + bulkErr := err.(schwift.BulkError) expectInt(t, bulkErr.StatusCode, 400) - expectString(t, bulkErr.ArchiveError, "Invalid Tar File: truncated header") + expectString(t, bulkErr.OverallError, "Invalid Tar File: truncated header") expectInt(t, len(bulkErr.ObjectErrors), 0) }) } @@ -87,7 +87,7 @@ func TestBulkUploadObjectError(t *testing.T) { ) expectInt(t, n, 1) expectError(t, err, "400 Bad Request (+1 object errors)") - bulkErr := err.(schwift.BulkUploadError) + bulkErr := err.(schwift.BulkError) expectInt(t, len(bulkErr.ObjectErrors), 1) expectString(t, bulkErr.ObjectErrors[0].ContainerName, c.Name()) expectInt(t, bulkErr.ObjectErrors[0].StatusCode, 400) |
