From b4680d8341733f48295ccf188f109cf69027a3f9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 19 Sep 2019 16:36:03 +0200 Subject: [PATCH] dashboard/app: fix error wrapping The current code does not do what it's supposed to do. Converting error to error is always true. Properly wrap errors. --- dashboard/app/handler.go | 6 +++--- dashboard/app/main.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dashboard/app/handler.go b/dashboard/app/handler.go index bd62d26f..e3d2b4aa 100644 --- a/dashboard/app/handler.go +++ b/dashboard/app/handler.go @@ -64,8 +64,8 @@ func handleContext(fn contextHandler) http.Handler { } type ( - ErrDontLog error - ErrRedirect error + ErrDontLog struct{ error } + ErrRedirect struct{ error } ) func handleAuth(fn contextHandler) contextHandler { @@ -188,7 +188,7 @@ func commonHeader(c context.Context, r *http.Request, w http.ResponseWriter, ns ns = adminPage } if ns != adminPage || !isAdminPage { - return nil, ErrRedirect(fmt.Errorf("/%v", ns)) + return nil, ErrRedirect{fmt.Errorf("/%v", ns)} } } if ns != adminPage { diff --git a/dashboard/app/main.go b/dashboard/app/main.go index 55d07766..e5e1db78 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -321,7 +321,7 @@ func handleBug(c context.Context, w http.ResponseWriter, r *http.Request) error return err } } else { - return ErrDontLog(fmt.Errorf("mandatory parameter id/extid is missing")) + return ErrDontLog{fmt.Errorf("mandatory parameter id/extid is missing")} } accessLevel := accessLevel(c, r) if err := checkAccessLevel(c, r, bug.sanitizeAccess(accessLevel)); err != nil { @@ -426,14 +426,14 @@ func handleTextImpl(c context.Context, w http.ResponseWriter, r *http.Request, t if x := r.FormValue("x"); x != "" { xid, err := strconv.ParseUint(x, 16, 64) if err != nil || xid == 0 { - return ErrDontLog(fmt.Errorf("failed to parse text id: %v", err)) + return ErrDontLog{fmt.Errorf("failed to parse text id: %v", err)} } id = int64(xid) } else { // Old link support, don't remove. xid, err := strconv.ParseInt(r.FormValue("id"), 10, 64) if err != nil || xid == 0 { - return ErrDontLog(fmt.Errorf("failed to parse text id: %v", err)) + return ErrDontLog{fmt.Errorf("failed to parse text id: %v", err)} } id = xid }