本文整理汇总了Golang中go/skia/org/infra/go/util.ReportError函数的典型用法代码示例。如果您正苦于以下问题:Golang ReportError函数的具体用法?Golang ReportError怎么用?Golang ReportError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReportError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: commitsHandler
// commitsHandler handles requests for commits.
//
// Queries look like:
//
// /commits/?begin=hash1&end=hash2
//
// or if there is only one hash:
//
// /commits/?begin=hash
//
// The response is HTML of the form:
//
// <pre>
// commit <a href="http://skia.googlesource....">5bdbd13d8833d23e0da552f6817ae0b5a4e849e5</a>
// Author: Joe Gregorio <[email protected]>
// Date: Wed Aug 6 16:16:18 2014 -0400
//
// Back to plotting lines.
//
// perf/go/skiaperf/perf.go
// perf/go/types/types.go
// perf/res/js/logic.js
//
// commit <a
// ...
// </pre>
//
func commitsHandler(w http.ResponseWriter, r *http.Request) {
glog.Infof("Query Handler: %q\n", r.URL.Path)
if r.Method != "GET" {
http.NotFound(w, r)
return
}
begin := r.FormValue("begin")
if len(begin) != 40 {
util.ReportError(w, r, fmt.Errorf("Invalid hash format: %s", begin), "Error while looking up hashes.")
return
}
end := r.FormValue("end")
body, err := git.Log(begin, end)
if err != nil {
util.ReportError(w, r, err, "Error while looking up hashes.")
return
}
escaped := ehtml.EscapeString(body)
linkified := commitLinkifyRe.ReplaceAllString(escaped, "<span class=subject>commit <a href=\"https://skia.googlesource.com/skia/+/${1}\" target=\"_blank\">${1}</a></span>")
w.Header().Set("Content-Type", "text/plain")
if _, err := w.Write([]byte(fmt.Sprintf("<pre>%s</pre>", linkified))); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
return
}
}
示例2: changeHandler
// changeHandler handles actions on individual services.
//
// The actions are forwarded off to the pulld service
// running on the machine hosting that service.
func changeHandler(w http.ResponseWriter, r *http.Request) {
if login.LoggedInAs(r) == "" {
util.ReportError(w, r, fmt.Errorf("You must be logged on to push."), "")
return
}
if err := r.ParseForm(); err != nil {
util.ReportError(w, r, err, "Failed to parse form.")
return
}
action := r.Form.Get("action")
name := r.Form.Get("name")
machine := ip.Resolve(r.Form.Get("machine"))
url := fmt.Sprintf("http://%s:10114/_/change?name=%s&action=%s", machine, name, action)
resp, err := client.Post(url, "", nil)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to reach %s: %v %s", machine, resp, err))
return
}
defer util.Close(resp.Body)
if resp.StatusCode != 200 {
util.ReportError(w, r, err, fmt.Sprintf("Failed to reach %s: %v %s", machine, resp, err))
return
}
w.Header().Set("Content-Type", "application/json")
if _, err := io.Copy(w, resp.Body); err != nil {
glog.Errorf("Failed to copy JSON error out: %s", err)
}
}
示例3: addCommitCommentHandler
func addCommitCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("addCommitCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
commit := mux.Vars(r)["commit"]
comment := struct {
Comment string `json:"comment"`
}{}
if err := json.NewDecoder(r.Body).Decode(&comment); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
defer util.Close(r.Body)
c := buildbot.CommitComment{
Commit: commit,
User: login.LoggedInAs(r),
Timestamp: time.Now().UTC(),
Message: comment.Comment,
}
if err := db.PutCommitComment(&c); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add commit comment: %v", err))
return
}
}
示例4: redirectHandler
// redirectHandler handles redirecting to the correct tradefed page.
func redirectHandler(w http.ResponseWriter, r *http.Request) {
if login.LoggedInAs(r) == "" {
r.Header.Set("Referer", r.URL.String())
http.Redirect(w, r, login.LoginURL(w, r), 302)
return
}
vars := mux.Vars(r)
codename := vars["codename"]
buildNumberStr := vars["buildNumber"]
target, err := codenameDB.Get([]byte(codename), nil)
if err != nil {
util.ReportError(w, r, err, "Not a valid target codename.")
return
}
buildNumber, err := strconv.Atoi(buildNumberStr)
if err != nil {
util.ReportError(w, r, err, "Not a valid build number.")
return
}
build, err := buildbot.GetBuildFromDB(string(codename), FAKE_MASTER, buildNumber)
if err != nil {
util.ReportError(w, r, err, "Could not find a matching build.")
}
id, ok := build.GetProperty("androidinternal_buildid").([]interface{})[1].(string)
if !ok {
util.ReportError(w, r, fmt.Errorf("Got %#v", id), "Could not find a matching build id.")
return
}
w.Header().Set("Content-Type", "text/html")
if _, err := w.Write([]byte(fmt.Sprintf(REDIRECT_TEMPLATE, codename, target, id, id, target, id, id, target))); err != nil {
glog.Errorf("Failed to write response: %s", err)
}
}
示例5: triageUndoHandler
// triageUndoHandler performs an "undo" for a given change id.
// The change id's are returned in the result of polyTriageLogHandler.
// It accepts one query parameter 'id' which is the id if the change
// that should be reversed.
// If successful it retunrs the same result as a call to polyTriageLogHandler
// to reflect the changed triagelog.
func triageUndoHandler(w http.ResponseWriter, r *http.Request) {
// Get the user and make sure they are logged in.
user := login.LoggedInAs(r)
if user == "" {
util.ReportError(w, r, fmt.Errorf("Not logged in."), "You must be logged in to change expectations.")
return
}
// Extract the id to undo.
changeID, err := strconv.Atoi(r.URL.Query().Get("id"))
if err != nil {
util.ReportError(w, r, err, "Invalid change id.")
return
}
// Do the undo procedure.
_, err = storages.ExpectationsStore.UndoChange(changeID, user)
if err != nil {
util.ReportError(w, r, err, "Unable to undo.")
return
}
// Send the same response as a query for the first page.
polyTriageLogHandler(w, r)
}
示例6: postAlertsJsonHandler
func postAlertsJsonHandler(w http.ResponseWriter, r *http.Request) {
// Get the alert ID.
alertIdStr, ok := mux.Vars(r)["alertId"]
if !ok {
util.ReportError(w, r, fmt.Errorf("No alert ID provided."), "No alert ID provided.")
return
}
alertId, err := strconv.ParseInt(alertIdStr, 10, 64)
if err != nil {
util.ReportError(w, r, fmt.Errorf("Invalid alert ID %s", alertIdStr), "Not found.")
return
}
var req struct {
Until int `json:"until"`
Comment string `json:"comment"`
}
defer util.Close(r.Body)
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
util.ReportError(w, r, err, "Failed to decode request body.")
return
}
handleAlert(alertId, req.Comment, req.Until, w, r)
}
示例7: clusteringHandler
// clusteringHandler handles doing the actual k-means clustering.
//
// The return format is JSON of the form:
//
// {
// "Clusters": [
// {
// "Keys": [
// "x86:GeForce320M:MacMini4.1:Mac10.8:GM_varied_text_clipped_no_lcd_640_480:8888",...],
// "ParamSummaries": [
// [{"Value": "Win8", "Weight": 15}, {"Value": "Android", "Weight": 14}, ...]
// ],
// "StepFit": {
// "LeastSquares":0.0006582442047814354,
// "TurningPoint":162,
// "StepSize":0.023272272692293046,
// "Regression": 35.3
// }
// Traces: [[[0, -0.00007967326606768456], [1, 0.011877665949459049], [2, 0.012158129176717419],...]]
// },
// ...
// ],
// "K": 5,
// "StdDevThreshhold": 0.1
// }
//
// Note that Keys contains all the keys, while Traces only contains traces of
// the N closest cluster members and the centroid.
//
// Takes the following query parameters:
//
// _k - The K to use for k-means clustering.
// _stddev - The standard deviation to use when normalize traces
// during k-means clustering.
// _issue - The Rietveld issue ID with trybot results to include.
//
// Additionally the rest of the query parameters as returned from
// sk.Query.selectionsAsQuery().
func clusteringHandler(w http.ResponseWriter, r *http.Request) {
glog.Infof("Clustering Handler: %q\n", r.URL.Path)
tile := masterTileBuilder.GetTile()
w.Header().Set("Content-Type", "application/json")
// If there are no query parameters just return with an empty set of ClusterSummaries.
if r.FormValue("_k") == "" || r.FormValue("_stddev") == "" {
writeClusterSummaries(clustering.NewClusterSummaries(), w, r)
return
}
k, err := strconv.ParseInt(r.FormValue("_k"), 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("_k parameter must be an integer %s.", r.FormValue("_k")))
return
}
stddev, err := strconv.ParseFloat(r.FormValue("_stddev"), 64)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("_stddev parameter must be a float %s.", r.FormValue("_stddev")))
return
}
issue := r.FormValue("_issue")
var tryResults *types.TryBotResults = nil
if issue != "" {
var err error
tryResults, err = trybot.Get(issue)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to get trybot data for clustering."))
return
}
}
delete(r.Form, "_k")
delete(r.Form, "_stddev")
delete(r.Form, "_issue")
// Create a filter function for traces that match the query parameters and
// optionally tryResults.
filter := func(key string, tr *types.PerfTrace) bool {
if tryResults != nil {
if _, ok := tryResults.Values[key]; !ok {
return false
}
}
return tiling.Matches(tr, r.Form)
}
if issue != "" {
if tile, err = trybot.TileWithTryData(tile, issue); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to get trybot data for clustering."))
return
}
}
summary, err := clustering.CalculateClusterSummaries(tile, int(k), stddev, filter)
if err != nil {
util.ReportError(w, r, err, "Failed to calculate clusters.")
return
}
writeClusterSummaries(summary, w, r)
}
示例8: shortcutHandler
// showcutHandler handles the POST requests of the shortcut page.
//
// Shortcuts are of the form:
//
// {
// "scale": 0,
// "tiles": [-1],
// "hash": "a1092123890...",
// "ids": [
// "x86:...",
// "x86:...",
// "x86:...",
// ]
// }
//
// hash - The git hash of where a step was detected. Can be null.
//
func shortcutHandler(w http.ResponseWriter, r *http.Request) {
// TODO(jcgregorio): Add unit tests.
match := shortcutHandlerPath.FindStringSubmatch(r.URL.Path)
if match == nil {
http.NotFound(w, r)
return
}
if r.Method == "POST" {
// check header
if ct := r.Header.Get("Content-Type"); ct != "application/json" {
util.ReportError(w, r, fmt.Errorf("Error: received %s", ct), "Invalid content type.")
return
}
defer util.Close(r.Body)
id, err := shortcut.Insert(r.Body)
if err != nil {
util.ReportError(w, r, err, "Error inserting shortcut.")
return
}
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
if err := enc.Encode(map[string]string{"id": id}); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
} else {
http.NotFound(w, r)
}
}
示例9: deleteBuildCommentHandler
func deleteBuildCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("deleteBuildCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
cache, err := getCommitCache(w, r)
if err != nil {
return
}
buildId, err := strconv.ParseInt(mux.Vars(r)["buildId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid build id: %v", err))
return
}
commentId, err := strconv.ParseInt(mux.Vars(r)["commentId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid comment id: %v", err))
return
}
if err := cache.DeleteBuildComment(int(buildId), int(commentId)); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to delete comment: %v", err))
return
}
}
示例10: shortCommitsHandler
// shortCommitsHandler returns basic info of a range of commits.
//
// Queries look like:
//
// /commits/?begin=hash1&end=hash2
//
// Response is JSON of ShortCommits format that looks like:
//
// {
// "commits": [
// {
// hash: "123abc",
// author: "bensong",
// subject: "Adds short commits."
// },
// ...
// ]
// }
//
func shortCommitsHandler(w http.ResponseWriter, r *http.Request) {
glog.Infof("Query Handler: %q\n", r.URL.Path)
if r.Method != "GET" {
http.NotFound(w, r)
return
}
begin := r.FormValue("begin")
if len(begin) != 40 {
util.ReportError(w, r, fmt.Errorf("Invalid begin hash format: %s", begin), "Error while looking up hashes.")
return
}
end := r.FormValue("end")
if len(end) != 40 {
util.ReportError(w, r, fmt.Errorf("Invalid end hash format: %s", end), "Error while looking up hashes.")
return
}
commits, err := git.ShortList(begin, end)
if err != nil {
util.ReportError(w, r, err, "Error while looking up hashes.")
return
}
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
if err := enc.Encode(commits); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
}
示例11: RedoTaskHandler
func RedoTaskHandler(prototype Task, w http.ResponseWriter, r *http.Request) {
if !ctfeutil.UserHasEditRights(r) {
skutil.ReportError(w, r, fmt.Errorf("Must have google or chromium account to redo tasks"), "")
return
}
w.Header().Set("Content-Type", "application/json")
vars := struct{ Id int64 }{}
if err := json.NewDecoder(r.Body).Decode(&vars); err != nil {
skutil.ReportError(w, r, err, "Failed to parse redo request")
return
}
defer skutil.Close(r.Body)
rowQuery := fmt.Sprintf("SELECT * FROM %s WHERE id = ? AND ts_completed IS NOT NULL", prototype.TableName())
binds := []interface{}{vars.Id}
data, err := prototype.Select(rowQuery, binds...)
if err != nil {
skutil.ReportError(w, r, err, "Unable to find requested task.")
return
}
tasks := AsTaskSlice(data)
if len(tasks) != 1 {
skutil.ReportError(w, r, err, "Unable to find requested task.")
return
}
addTaskVars := tasks[0].GetPopulatedAddTaskVars()
// Replace the username with the new requester.
addTaskVars.GetAddTaskCommonVars().Username = login.LoggedInAs(r)
if _, err := AddTask(addTaskVars); err != nil {
skutil.ReportError(w, r, err, "Could not redo the task.")
return
}
}
示例12: addBuildCommentHandler
func addBuildCommentHandler(w http.ResponseWriter, r *http.Request) {
defer timer.New("addBuildCommentHandler").Stop()
if !userHasEditRights(r) {
util.ReportError(w, r, fmt.Errorf("User does not have edit rights."), "User does not have edit rights.")
return
}
w.Header().Set("Content-Type", "application/json")
cache, err := getCommitCache(w, r)
if err != nil {
return
}
buildId, err := strconv.ParseInt(mux.Vars(r)["buildId"], 10, 32)
if err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Invalid build id: %v", err))
return
}
comment := struct {
Comment string `json:"comment"`
}{}
if err := json.NewDecoder(r.Body).Decode(&comment); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
defer util.Close(r.Body)
c := buildbot.BuildComment{
BuildId: int(buildId),
User: login.LoggedInAs(r),
Timestamp: float64(time.Now().UTC().Unix()),
Message: comment.Comment,
}
if err := cache.AddBuildComment(int(buildId), &c); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed to add comment: %v", err))
return
}
}
示例13: calcHandler
// calcHandler handles requests for the form:
//
// /calc/?formula=filter("config=8888")
//
// Where the formula is any formula that parser.Eval() accepts.
//
// The response is the same format as queryHandler.
func calcHandler(w http.ResponseWriter, r *http.Request) {
glog.Infof("Calc Handler: %q\n", r.URL.Path)
w.Header().Set("Content-Type", "application/json")
tile := masterTileBuilder.GetTile()
formula := r.FormValue("formula")
var data interface{} = nil
if r.FormValue("flat") == "true" {
resp := &FlatQueryResponse{
Traces: []*types.PerfTrace{},
}
if err := addFlatCalculatedTraces(resp, tile, formula); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed in /calc/ to evaluate formula."))
return
}
data = resp
} else {
resp := &QueryResponse{
Traces: []*tiling.TraceGUI{},
Hash: "",
}
if err := addCalculatedTraces(resp, tile, formula); err != nil {
util.ReportError(w, r, err, fmt.Sprintf("Failed in /calc/ to evaluate formula."))
return
}
data = resp
}
enc := json.NewEncoder(w)
if err := enc.Encode(data); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
return
}
}
示例14: getOldestPendingTaskHandler
func getOldestPendingTaskHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
tasks, err := getAllPendingTasks()
if err != nil {
skutil.ReportError(w, r, err, fmt.Sprintf("Failed to get all pending tasks: %v", err))
return
}
var oldestTask task_common.Task
for _, task := range tasks {
if oldestTask == nil {
oldestTask = task
} else if oldestTask.GetCommonCols().TsAdded.Int64 <
task.GetCommonCols().TsAdded.Int64 {
oldestTask = task
}
}
oldestTaskJsonRepr := map[string]task_common.Task{}
if oldestTask != nil {
oldestTaskJsonRepr[oldestTask.GetTaskName()] = oldestTask
}
if err := json.NewEncoder(w).Encode(oldestTaskJsonRepr); err != nil {
skutil.ReportError(w, r, err, fmt.Sprintf("Failed to encode JSON: %v", err))
return
}
}
示例15: handleAlerts
func handleAlerts(w http.ResponseWriter, r *http.Request, title string, categories []string, excludeCategories []string) {
w.Header().Set("Content-Type", "text/html")
// Don't use cached templates in testing mode.
if *testing {
reloadTemplates()
}
categoriesJson, err := json.Marshal(categories)
if err != nil {
util.ReportError(w, r, fmt.Errorf("Failed to encode JSON."), "Failed to encode JSON")
}
excludeJson, err := json.Marshal(excludeCategories)
if err != nil {
util.ReportError(w, r, fmt.Errorf("Failed to encode JSON."), "Failed to encode JSON")
}
inp := struct {
Categories string
ExcludeCategories string
Title string
}{
Categories: string(categoriesJson),
ExcludeCategories: string(excludeJson),
Title: title,
}
if err := alertsTemplate.Execute(w, inp); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
}