1
0
mirror of https://github.com/golang/go synced 2024-11-20 07:14:40 -07:00

cmd/trace: log errors to console in AJAX handler

Fixes #11508

Change-Id: I72e83893b76f75685d6edfe65ca6691d97539226
Reviewed-on: https://go-review.googlesource.com/11864
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Dmitry Vyukov 2015-07-02 20:33:30 +02:00
parent 2a0fc9e70e
commit 11f50f41ee

View File

@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"internal/trace"
"log"
"net/http"
"os"
"path/filepath"
@ -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
}
@ -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)
@ -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
}
}