dashboard/app: fix misspelled field in template

Also change code to catch such bugs in tests in future.
The problem was that template.Execute already wrote something
into w before returning error, so though the function
returned an error we served 200 instead of 500.
This commit is contained in:
Dmitry Vyukov 2017-12-01 14:20:03 +01:00
parent 2fa91450df
commit a6f9669d26
3 changed files with 13 additions and 3 deletions

View File

@ -4,6 +4,7 @@
package dash
import (
"bytes"
"fmt"
"html/template"
"net/http"
@ -53,6 +54,15 @@ func handleAuth(fn contextHandler) contextHandler {
}
}
func serveTemplate(w http.ResponseWriter, name string, data interface{}) error {
buf := new(bytes.Buffer)
if err := templates.ExecuteTemplate(buf, name, data); err != nil {
return err
}
w.Write(buf.Bytes())
return nil
}
type uiHeader struct {
}

View File

@ -149,7 +149,7 @@ func handleMain(c context.Context, w http.ResponseWriter, r *http.Request) error
Jobs: jobs,
BugGroups: groups,
}
return templates.ExecuteTemplate(w, "main.html", data)
return serveTemplate(w, "main.html", data)
}
// handleBug serves page about a single bug (which is passed in id argument).
@ -191,7 +191,7 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error
Bug: uiBug,
Crashes: crashes,
}
return templates.ExecuteTemplate(w, "bug.html", data)
return serveTemplate(w, "bug.html", data)
}
// handleText serves plain text blobs (crash logs, reports, reproducers, etc).

View File

@ -98,7 +98,7 @@
</tr>
{{range $job := $.Jobs}}
<tr>
<td class="time">{{if $job.Link}}<a href="{{$job.Link}}">{{formatTime $job.Created}}</a>{{else}}{{formatTime $job.Created}}{{end}}</td>
<td class="time">{{if $job.ExternalLink}}<a href="{{$job.ExternalLink}}">{{formatTime $job.Created}}</a>{{else}}{{formatTime $job.Created}}{{end}}</td>
<td class="time">{{formatTime $job.Started}}{{if gt $job.Attempts 1}} ({{$job.Attempts}}){{end}}</td>
<td class="time">{{formatTime $job.Finished}}</td>
<td>{{$job.User}}</td>