Commit 41510837 authored by Jacob Vosmaer's avatar Jacob Vosmaer Committed by Nick Thomas

Shorten error messages to D&K style

parent 545a9b6e
...@@ -76,7 +76,7 @@ func NewMultipart(ctx context.Context, partURLs []string, completeURL, abortURL, ...@@ -76,7 +76,7 @@ func NewMultipart(ctx context.Context, partURLs []string, completeURL, abortURL,
n, err := io.Copy(ioutil.Discard, pr) n, err := io.Copy(ioutil.Discard, pr)
if err != nil { if err != nil {
m.uploadError = fmt.Errorf("cannot drain pipe: %v", err) m.uploadError = fmt.Errorf("drain pipe: %v", err)
return return
} }
if n > 0 { if n > 0 {
...@@ -120,12 +120,12 @@ func (m *Multipart) cleanup(ctx context.Context) { ...@@ -120,12 +120,12 @@ func (m *Multipart) cleanup(ctx context.Context) {
func (m *Multipart) complete(cmu *CompleteMultipartUpload) error { func (m *Multipart) complete(cmu *CompleteMultipartUpload) error {
body, err := xml.Marshal(cmu) body, err := xml.Marshal(cmu)
if err != nil { if err != nil {
return fmt.Errorf("cannot marshal CompleteMultipartUpload request: %v", err) return fmt.Errorf("marshal CompleteMultipartUpload request: %v", err)
} }
req, err := http.NewRequest("POST", m.CompleteURL, bytes.NewReader(body)) req, err := http.NewRequest("POST", m.CompleteURL, bytes.NewReader(body))
if err != nil { if err != nil {
return fmt.Errorf("cannot create CompleteMultipartUpload request: %v", err) return fmt.Errorf("create CompleteMultipartUpload request: %v", err)
} }
req.ContentLength = int64(len(body)) req.ContentLength = int64(len(body))
req.Header.Set("Content-Type", "application/xml") req.Header.Set("Content-Type", "application/xml")
...@@ -144,7 +144,7 @@ func (m *Multipart) complete(cmu *CompleteMultipartUpload) error { ...@@ -144,7 +144,7 @@ func (m *Multipart) complete(cmu *CompleteMultipartUpload) error {
result := &compoundCompleteMultipartUploadResult{} result := &compoundCompleteMultipartUploadResult{}
decoder := xml.NewDecoder(resp.Body) decoder := xml.NewDecoder(resp.Body)
if err := decoder.Decode(&result); err != nil { if err := decoder.Decode(&result); err != nil {
return fmt.Errorf("cannot decode CompleteMultipartUpload answer: %v", err) return fmt.Errorf("decode CompleteMultipartUpload answer: %v", err)
} }
if result.isError() { if result.isError() {
...@@ -152,7 +152,7 @@ func (m *Multipart) complete(cmu *CompleteMultipartUpload) error { ...@@ -152,7 +152,7 @@ func (m *Multipart) complete(cmu *CompleteMultipartUpload) error {
} }
if result.CompleteMultipartUploadResult == nil { if result.CompleteMultipartUploadResult == nil {
return fmt.Errorf("cannot read CompleteMultipartUpload answer") return fmt.Errorf("empty CompleteMultipartUploadResult")
} }
m.extractETag(result.ETag) m.extractETag(result.ETag)
...@@ -178,7 +178,7 @@ func (m *Multipart) verifyETag(cmu *CompleteMultipartUpload) error { ...@@ -178,7 +178,7 @@ func (m *Multipart) verifyETag(cmu *CompleteMultipartUpload) error {
func (m *Multipart) readAndUploadOnePart(partURL string, putHeaders map[string]string, src io.Reader, partNumber int) (*completeMultipartUploadPart, error) { func (m *Multipart) readAndUploadOnePart(partURL string, putHeaders map[string]string, src io.Reader, partNumber int) (*completeMultipartUploadPart, error) {
file, err := ioutil.TempFile("", "part-buffer") file, err := ioutil.TempFile("", "part-buffer")
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to create a temporary file for buffering: %v", err) return nil, fmt.Errorf("create temporary buffer file: %v", err)
} }
defer func(path string) { defer func(path string) {
if err := os.Remove(path); err != nil { if err := os.Remove(path); err != nil {
...@@ -188,19 +188,19 @@ func (m *Multipart) readAndUploadOnePart(partURL string, putHeaders map[string]s ...@@ -188,19 +188,19 @@ func (m *Multipart) readAndUploadOnePart(partURL string, putHeaders map[string]s
n, err := io.Copy(file, src) n, err := io.Copy(file, src)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot write part %d to disk: %v", partNumber, err) return nil, fmt.Errorf("write part %d to disk: %v", partNumber, err)
} }
if n == 0 { if n == 0 {
return nil, nil return nil, nil
} }
if _, err = file.Seek(0, io.SeekStart); err != nil { if _, err = file.Seek(0, io.SeekStart); err != nil {
return nil, fmt.Errorf("cannot rewind part %d temporary dump : %v", partNumber, err) return nil, fmt.Errorf("rewind part %d temporary dump : %v", partNumber, err)
} }
etag, err := m.uploadPart(partURL, putHeaders, file, n) etag, err := m.uploadPart(partURL, putHeaders, file, n)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot upload part %d: %v", partNumber, err) return nil, fmt.Errorf("upload part %d: %v", partNumber, err)
} }
return &completeMultipartUploadPart{PartNumber: partNumber, ETag: etag}, nil return &completeMultipartUploadPart{PartNumber: partNumber, ETag: etag}, nil
} }
......
...@@ -132,7 +132,7 @@ func sendFileFromDisk(w http.ResponseWriter, r *http.Request, file string) { ...@@ -132,7 +132,7 @@ func sendFileFromDisk(w http.ResponseWriter, r *http.Request, file string) {
if contentTypeHeaderPresent { if contentTypeHeaderPresent {
data, err := ioutil.ReadAll(io.LimitReader(content, headers.MaxDetectSize)) data, err := ioutil.ReadAll(io.LimitReader(content, headers.MaxDetectSize))
if err != nil { if err != nil {
helper.Fail500(w, r, fmt.Errorf("error reading the file")) helper.Fail500(w, r, fmt.Errorf("content type detection: %v", err))
return return
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment