From f9e6d61a378f81bd52e3a9d7afc4e75d36686e78 Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Wed, 20 Dec 2017 19:31:28 +0900 Subject: [PATCH] don't log ERROR in ReportHandler when repo not found in cache --- handlers/checks.go | 10 +++++++++- handlers/report.go | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/handlers/checks.go b/handlers/checks.go index ec2df20..b386d08 100644 --- a/handlers/checks.go +++ b/handlers/checks.go @@ -14,6 +14,14 @@ import ( "github.com/gojp/goreportcard/download" ) +type notFoundError struct { + repo string +} + +func (n notFoundError) Error() string { + return fmt.Sprintf("%q not found in cache", n.repo) +} + func dirName(repo string) string { return fmt.Sprintf("_repos/src/%s", repo) } @@ -34,7 +42,7 @@ func getFromCache(repo string) (checksResp, error) { } cached := b.Get([]byte(repo)) if cached == nil { - return fmt.Errorf("%q not found in cache", repo) + return notFoundError{repo} } err = json.Unmarshal(cached, &resp) diff --git a/handlers/report.go b/handlers/report.go index b9e17fc..272411e 100644 --- a/handlers/report.go +++ b/handlers/report.go @@ -19,7 +19,12 @@ func ReportHandler(w http.ResponseWriter, r *http.Request, repo string, dev bool resp, err := getFromCache(repo) needToLoad := false if err != nil { - log.Println("ERROR ReportHandler:", err) // log error, but continue + switch err.(type) { + case notFoundError: + // don't bother logging - we already log in getFromCache. continue + default: + log.Println("ERROR ReportHandler:", err) // log error, but continue + } needToLoad = true }