Commit 4fe063cf authored by Jacob Vosmaer's avatar Jacob Vosmaer

Improve error messages

parent 1bb40cdf
...@@ -61,7 +61,7 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea ...@@ -61,7 +61,7 @@ func unpackFileFromZip(archiveFileName, encodedFilename string, headers http.Hea
headers.Set("Content-Disposition", "attachment; filename=\""+escapeQuotes(basename)+"\"") headers.Set("Content-Disposition", "attachment; filename=\""+escapeQuotes(basename)+"\"")
// Copy file body to client // Copy file body to client
if _, err := io.Copy(output, reader); err != nil { if _, err := io.Copy(output, reader); err != nil {
return fmt.Errorf("copy %v stdout: %v", catFile.Args, err) return fmt.Errorf("copy stdout of %v: %v", catFile.Args, err)
} }
return waitCatFile(catFile) return waitCatFile(catFile)
......
...@@ -111,7 +111,7 @@ func handleGetArchive(w http.ResponseWriter, r *http.Request, a *api.Response) { ...@@ -111,7 +111,7 @@ func handleGetArchive(w http.ResponseWriter, r *http.Request, a *api.Response) {
setArchiveHeaders(w, format, archiveFilename) setArchiveHeaders(w, format, archiveFilename)
w.WriteHeader(200) // Don't bother with HTTP 500 from this point on, just return w.WriteHeader(200) // Don't bother with HTTP 500 from this point on, just return
if _, err := io.Copy(w, archiveReader); err != nil { if _, err := io.Copy(w, archiveReader); err != nil {
helper.LogError(fmt.Errorf("handleGetArchive: read: %v", err)) helper.LogError(fmt.Errorf("handleGetArchive: copy 'git archive' output: %v", err))
return return
} }
if err := archiveCmd.Wait(); err != nil { if err := archiveCmd.Wait(); err != nil {
......
...@@ -87,7 +87,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *api.Response) ...@@ -87,7 +87,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *api.Response)
return return
} }
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
helper.LogError(fmt.Errorf("handleGetInfoRefs: read from %v: %v", cmd.Args, err)) helper.LogError(fmt.Errorf("handleGetInfoRefs: copy output of %v: %v", cmd.Args, err))
return return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
...@@ -146,7 +146,7 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) { ...@@ -146,7 +146,7 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
// This io.Copy may take a long time, both for Git push and pull. // This io.Copy may take a long time, both for Git push and pull.
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
helper.LogError(fmt.Errorf("handlePostRPC read from %v: %v", cmd.Args, err)) helper.LogError(fmt.Errorf("handlePostRPC copy output of %v: %v", cmd.Args, err))
return return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
......
...@@ -61,7 +61,7 @@ func handleStoreLfsObject(h http.Handler) api.HandleFunc { ...@@ -61,7 +61,7 @@ func handleStoreLfsObject(h http.Handler) api.HandleFunc {
written, err := io.Copy(hw, r.Body) written, err := io.Copy(hw, r.Body)
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("handleStoreLfsObject: write tempfile: %v", err)) helper.Fail500(w, fmt.Errorf("handleStoreLfsObject: copy body to tempfile: %v", err))
return return
} }
file.Close() file.Close()
......
...@@ -20,7 +20,11 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -20,7 +20,11 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
// Create multipart reader // Create multipart reader
reader, err := r.MultipartReader() reader, err := r.MultipartReader()
if err != nil { if err != nil {
return nil, err if err == http.ErrNotMultipart {
// We want to be able to recognize http.ErrNotMultipart elsewhere so no fmt.Errorf
return nil, http.ErrNotMultipart
}
return nil, fmt.Errorf("get multipart reader: %v", err)
} }
var files []string var files []string
...@@ -53,13 +57,13 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -53,13 +57,13 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
if filename := p.FileName(); filename != "" { if filename := p.FileName(); filename != "" {
// Create temporary directory where the uploaded file will be stored // Create temporary directory where the uploaded file will be stored
if err := os.MkdirAll(tempPath, 0700); err != nil { if err := os.MkdirAll(tempPath, 0700); err != nil {
return cleanup, err return cleanup, fmt.Errorf("mkdir for tempfile: %v", err)
} }
// Create temporary file in path returned by Authorization filter // Create temporary file in path returned by Authorization filter
file, err := ioutil.TempFile(tempPath, "upload_") file, err := ioutil.TempFile(tempPath, "upload_")
if err != nil { if err != nil {
return cleanup, err return cleanup, fmt.Errorf("create tempfile: %v", err)
} }
defer file.Close() defer file.Close()
...@@ -70,7 +74,7 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -70,7 +74,7 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
_, err = io.Copy(file, p) _, err = io.Copy(file, p)
if err != nil { if err != nil {
return cleanup, err return cleanup, fmt.Errorf("copy from multipart to tempfile: %v", err)
} }
file.Close() file.Close()
...@@ -81,16 +85,16 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -81,16 +85,16 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
} else { } else {
np, err := writer.CreatePart(p.Header) np, err := writer.CreatePart(p.Header)
if err != nil { if err != nil {
return cleanup, err return cleanup, fmt.Errorf("create multipart field: %v", err)
} }
_, err = io.Copy(np, p) _, err = io.Copy(np, p)
if err != nil { if err != nil {
return cleanup, err return cleanup, fmt.Errorf("duplicate multipart field: %v", err)
} }
if err := filter.ProcessField(name, writer); err != nil { if err := filter.ProcessField(name, writer); err != nil {
return cleanup, err return cleanup, fmt.Errorf("process multipart field: %v", err)
} }
} }
} }
...@@ -99,7 +103,7 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te ...@@ -99,7 +103,7 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
func HandleFileUploads(w http.ResponseWriter, r *http.Request, h http.Handler, tempPath string, filter MultipartFormProcessor) { func HandleFileUploads(w http.ResponseWriter, r *http.Request, h http.Handler, tempPath string, filter MultipartFormProcessor) {
if tempPath == "" { if tempPath == "" {
helper.Fail500(w, fmt.Errorf("handleFileUploads: temporary path not defined")) helper.Fail500(w, fmt.Errorf("handleFileUploads: tempPath empty"))
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