From 32e9dd2dfdf7179c2f83772f9d09bbfcdd5011f3 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 1 Nov 2021 22:06:12 +0000 Subject: [PATCH] dawn_node: Improve error handling for run-cts Rebuild if the `out-node` directory is missing. Actually check the server's status code. Fix error handling for bad statuses. Change-Id: I2164bba528036d39f10852f4ffd8ace76f145dba Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/67780 Reviewed-by: Antonio Maiorano Commit-Queue: Ben Clayton --- src/dawn_node/tools/src/cmd/run-cts/main.go | 56 +++++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/dawn_node/tools/src/cmd/run-cts/main.go b/src/dawn_node/tools/src/cmd/run-cts/main.go index 8ed76d7f17..1570d9f52e 100644 --- a/src/dawn_node/tools/src/cmd/run-cts/main.go +++ b/src/dawn_node/tools/src/cmd/run-cts/main.go @@ -23,6 +23,7 @@ import ( "flag" "fmt" "io" + "io/ioutil" "math" "net/http" "os" @@ -174,7 +175,8 @@ func run() error { return fmt.Errorf("failed to scan source files for modified timestamps: %w", err) } - ctsNeedsRebuild := mostRecentSourceChange.After(cache.BuildTimestamp) + ctsNeedsRebuild := mostRecentSourceChange.After(cache.BuildTimestamp) || + !isDir(filepath.Join(r.cts, "out-node")) if build { if verbose { fmt.Println("CTS needs rebuild:", ctsNeedsRebuild) @@ -491,29 +493,39 @@ func (r *runner) runServer(caseIndices <-chan int, results chan<- result) error continue } - var resp Response - if err := json.NewDecoder(postResp.Body).Decode(&resp); err != nil { - res.error = fmt.Errorf("server response decode failure") - res.status = fail - results <- res - continue - } + if postResp.StatusCode == http.StatusOK { + var resp Response + if err := json.NewDecoder(postResp.Body).Decode(&resp); err != nil { + res.error = fmt.Errorf("server response decode failure") + res.status = fail + results <- res + continue + } - switch resp.Status { - case "pass": - res.status = pass - res.message = resp.Message - case "warn": - res.status = warn - res.message = resp.Message - case "fail": + switch resp.Status { + case "pass": + res.status = pass + res.message = resp.Message + case "warn": + res.status = warn + res.message = resp.Message + case "fail": + res.status = fail + res.message = resp.Message + case "skip": + res.status = skip + res.message = resp.Message + default: + res.status = fail + res.error = fmt.Errorf("unknown status: '%v'", resp.Status) + } + } else { + msg, err := ioutil.ReadAll(postResp.Body) + if err != nil { + msg = []byte(err.Error()) + } res.status = fail - res.message = resp.Message - case "skip": - res.status = skip - res.message = resp.Message - default: - err = fmt.Errorf("unknown status: '%v'", resp.Status) + res.error = fmt.Errorf("server error: %v", string(msg)) } results <- res }