mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-21 12:01:00 +00:00
syz-manager: better handle errors in HTML templates
I periodically see: 2020/08/23 13:33:21 http: superfluous response.WriteHeader call from main.(*Manager).httpSummary (html.go:72) which suggest that there are some erros during template execution. But currently we don't seem to show them properly. Show them properly and also log.
This commit is contained in:
parent
4b4ae700b3
commit
67b599d167
@ -5,8 +5,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -67,12 +69,7 @@ func (mgr *Manager) httpSummary(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, fmt.Sprintf("failed to collect crashes: %v", err), http.StatusInternalServerError)
|
http.Error(w, fmt.Sprintf("failed to collect crashes: %v", err), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
executeTemplate(w, summaryTemplate, data)
|
||||||
if err := summaryTemplate.Execute(w, data); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err),
|
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) httpConfig(w http.ResponseWriter, r *http.Request) {
|
func (mgr *Manager) httpConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -99,11 +96,7 @@ func (mgr *Manager) httpSyscalls(w http.ResponseWriter, r *http.Request) {
|
|||||||
sort.Slice(data.Calls, func(i, j int) bool {
|
sort.Slice(data.Calls, func(i, j int) bool {
|
||||||
return data.Calls[i].Name < data.Calls[j].Name
|
return data.Calls[i].Name < data.Calls[j].Name
|
||||||
})
|
})
|
||||||
if err := syscallsTemplate.Execute(w, data); err != nil {
|
executeTemplate(w, syscallsTemplate, data)
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err),
|
|
||||||
http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) collectStats() []UIStat {
|
func (mgr *Manager) collectStats() []UIStat {
|
||||||
@ -168,10 +161,7 @@ func (mgr *Manager) httpCrash(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "failed to read crash info", http.StatusInternalServerError)
|
http.Error(w, "failed to read crash info", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := crashTemplate.Execute(w, crash); err != nil {
|
executeTemplate(w, crashTemplate, crash)
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) httpCorpus(w http.ResponseWriter, r *http.Request) {
|
func (mgr *Manager) httpCorpus(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -203,11 +193,7 @@ func (mgr *Manager) httpCorpus(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
return a.Short < b.Short
|
return a.Short < b.Short
|
||||||
})
|
})
|
||||||
|
executeTemplate(w, corpusTemplate, data)
|
||||||
if err := corpusTemplate.Execute(w, data); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) httpCover(w http.ResponseWriter, r *http.Request) {
|
func (mgr *Manager) httpCover(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -282,11 +268,7 @@ func (mgr *Manager) httpCoverFallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
sort.Slice(data.Calls, func(i, j int) bool {
|
sort.Slice(data.Calls, func(i, j int) bool {
|
||||||
return data.Calls[i].Name < data.Calls[j].Name
|
return data.Calls[i].Name < data.Calls[j].Name
|
||||||
})
|
})
|
||||||
|
executeTemplate(w, fallbackCoverTemplate, data)
|
||||||
if err := fallbackCoverTemplate.Execute(w, data); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) httpPrio(w http.ResponseWriter, r *http.Request) {
|
func (mgr *Manager) httpPrio(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -318,11 +300,7 @@ func (mgr *Manager) httpPrio(w http.ResponseWriter, r *http.Request) {
|
|||||||
sort.Slice(data.Prios, func(i, j int) bool {
|
sort.Slice(data.Prios, func(i, j int) bool {
|
||||||
return data.Prios[i].Prio > data.Prios[j].Prio
|
return data.Prios[i].Prio > data.Prios[j].Prio
|
||||||
})
|
})
|
||||||
|
executeTemplate(w, prioTemplate, data)
|
||||||
if err := prioTemplate.Execute(w, data); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) httpFile(w http.ResponseWriter, r *http.Request) {
|
func (mgr *Manager) httpFile(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -539,6 +517,16 @@ func reproStatus(hasRepro, hasCRepro, reproducing, nonReproducible bool) string
|
|||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func executeTemplate(w http.ResponseWriter, templ *template.Template, data interface{}) {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
if err := templ.Execute(buf, data); err != nil {
|
||||||
|
log.Logf(0, "failed to execute template: %v", err)
|
||||||
|
http.Error(w, fmt.Sprintf("failed to execute template: %v", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Write(buf.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
func trimNewLines(data []byte) []byte {
|
func trimNewLines(data []byte) []byte {
|
||||||
for len(data) > 0 && data[len(data)-1] == '\n' {
|
for len(data) > 0 && data[len(data)-1] == '\n' {
|
||||||
data = data[:len(data)-1]
|
data = data[:len(data)-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user