Commit c111e8aa authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add logError function

parent d88bb4df
...@@ -103,22 +103,22 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) { ...@@ -103,22 +103,22 @@ func handleGetArchive(w http.ResponseWriter, r *gitRequest) {
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 {
log.Printf("handleGetArchive: read: %v", err) logError(fmt.Errorf("handleGetArchive: read: %v", err))
return return
} }
if err := archiveCmd.Wait(); err != nil { if err := archiveCmd.Wait(); err != nil {
log.Printf("handleGetArchive: archiveCmd: %v", err) logError(fmt.Errorf("handleGetArchive: archiveCmd: %v", err))
return return
} }
if compressCmd != nil { if compressCmd != nil {
if err := compressCmd.Wait(); err != nil { if err := compressCmd.Wait(); err != nil {
log.Printf("handleGetArchive: compressCmd: %v", err) logError(fmt.Errorf("handleGetArchive: compressCmd: %v", err))
return return
} }
} }
if err := finalizeCachedArchive(tempFile, r.ArchivePath); err != nil { if err := finalizeCachedArchive(tempFile, r.ArchivePath); err != nil {
log.Printf("handleGetArchive: finalize cached archive: %v", err) logError(fmt.Errorf("handleGetArchive: finalize cached archive: %v", err))
return return
} }
} }
......
...@@ -7,7 +7,6 @@ package main ...@@ -7,7 +7,6 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -40,19 +39,19 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) { ...@@ -40,19 +39,19 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest) {
w.Header().Add("Cache-Control", "no-cache") w.Header().Add("Cache-Control", "no-cache")
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 := pktLine(w, fmt.Sprintf("# service=%s\n", rpc)); err != nil { if err := pktLine(w, fmt.Sprintf("# service=%s\n", rpc)); err != nil {
log.Printf("handleGetInfoRefs: pktLine: %v", err) logError(fmt.Errorf("handleGetInfoRefs: pktLine: %v", err))
return return
} }
if err := pktFlush(w); err != nil { if err := pktFlush(w); err != nil {
log.Printf("handleGetInfoRefs: pktFlush: %v", err) logError(fmt.Errorf("handleGetInfoRefs: pktFlush: %v", err))
return return
} }
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
log.Printf("handleGetInfoRefs: read from %v: %v", cmd.Args, err) logError(fmt.Errorf("handleGetInfoRefs: read from %v: %v", cmd.Args, err))
return return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
log.Printf("handleGetInfoRefs: wait for %v: %v", cmd.Args, err) logError(fmt.Errorf("handleGetInfoRefs: wait for %v: %v", cmd.Args, err))
return return
} }
} }
...@@ -107,11 +106,11 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) { ...@@ -107,11 +106,11 @@ func handlePostRPC(w http.ResponseWriter, r *gitRequest) {
// 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 {
log.Printf("handlePostRPC read from %v:%v", cmd.Args, err) logError(fmt.Errorf("handlePostRPC read from %v: %v", cmd.Args, err))
return return
} }
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
log.Printf("handlePostRPC wait for %v: %v", cmd.Args, err) logError(fmt.Errorf("handlePostRPC wait for %v: %v", cmd.Args, err))
return return
} }
} }
......
...@@ -19,12 +19,16 @@ import ( ...@@ -19,12 +19,16 @@ import (
func fail400(w http.ResponseWriter, err error) { func fail400(w http.ResponseWriter, err error) {
http.Error(w, "Bad request", 400) http.Error(w, "Bad request", 400)
log.Print(err) logError(err)
} }
func fail500(w http.ResponseWriter, err error) { func fail500(w http.ResponseWriter, err error) {
http.Error(w, "Internal server error", 500) http.Error(w, "Internal server error", 500)
log.Print(err) logError(err)
}
func logError(err error) {
log.Printf("error: %v", err)
} }
// Git subprocess helpers // Git subprocess helpers
......
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