Skip to content

Commit

Permalink
cmd/trace: log errors to console in AJAX handler
Browse files Browse the repository at this point in the history
Fixes golang#11508

Change-Id: I72e83893b76f75685d6edfe65ca6691d97539226
Reviewed-on: https://go-review.googlesource.com/11864
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
dvyukov committed Jul 2, 2015
1 parent 2a0fc9e commit 11f50f4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cmd/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"internal/trace"
"log"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -67,9 +68,10 @@ func httpTraceViewerHTML(w http.ResponseWriter, r *http.Request) {

// httpJsonTrace serves json trace, requested from within templTrace HTML.
func httpJsonTrace(w http.ResponseWriter, r *http.Request) {
// This is an AJAX handler, so instead of http.Error we use log.Printf to log errors.
events, err := parseEvents()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Printf("failed to parse trace: %v", err)
return
}

Expand All @@ -81,7 +83,7 @@ func httpJsonTrace(w http.ResponseWriter, r *http.Request) {
if goids := r.FormValue("goid"); goids != "" {
goid, err := strconv.ParseUint(goids, 10, 64)
if err != nil {
http.Error(w, fmt.Sprintf("failed to parse goid parameter '%v': %v", goids, err), http.StatusInternalServerError)
log.Printf("failed to parse goid parameter '%v': %v", goids, err)
return
}
analyzeGoroutines(events)
Expand All @@ -95,7 +97,7 @@ func httpJsonTrace(w http.ResponseWriter, r *http.Request) {

err = json.NewEncoder(w).Encode(generateTrace(params))
if err != nil {
http.Error(w, fmt.Sprintf("failed to serialize trace: %v", err), http.StatusInternalServerError)
log.Printf("failed to serialize trace: %v", err)
return
}
}
Expand Down

0 comments on commit 11f50f4

Please sign in to comment.